-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberToRomanConverter.html
More file actions
154 lines (134 loc) · 4.24 KB
/
NumberToRomanConverter.html
File metadata and controls
154 lines (134 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Number To Roman Converter</title>
<!-- Add Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KyZXEJv3v1iooF1QsMCQXM4V8ZQdpROoOnwyyj4zvc9t+Kn0rjsZmno+fqtcwsdr" crossorigin="anonymous">
<!-- Google Font for Roboto -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<style>
body {
background-color: #d4edda;
/* Light pastel green background */
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
max-width: 450px;
padding: 3em 2em;
border-radius: 0.8em;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
/* Slight shadow for the container */
}
.input-wrapper {
display: flex;
gap: 1em;
}
input {
padding: 1em 0.5em;
color: #5a5a5a;
/* Darker text color for input */
border: 2px solid #B0C4DE;
/* Soft gray-blue border */
}
input:focus {
border-color: #A2C2E1;
/* Lighter blue when focused */
}
button {
border: none;
background-color: #6495ED;
/* Soft blue button color */
color: #ffffff;
padding: 1em 1.5em;
font-size: 1em;
cursor: pointer;
}
input,
button {
font-size: 1em;
outline: none;
border-radius: 0.5em;
}
#output {
font-size: 1.2em;
text-align: center;
font-weight: 600;
color: #5a5a5a;
margin-top: 2em;
}
#output span {
font-size: 0.9em;
}
</style>
</head>
<body>
<div class="container text-center">
<h3 class="mb-4">Number To Roman Converter</h3>
<div class="input-wrapper mb-4">
<input type="number" id="input" class="form-control" placeholder="Enter Number Here..." />
<button type="submit" id="submit" class="btn btn-primary">Convert</button>
</div>
<p id="output">
<span>Enter The Number & Hit Convert</span>
</p>
</div>
<!-- Add Bootstrap JS -->
integrity="sha384-v1RkRgtAKY3Acf69XvbmI9wQmsZITFEokvmwn4L1lXrt5yF5VUwklC7uDPk2aFsg"
crossorigin="anonymous"></script>
<script>
let input = document.getElementById("input");
let button = document.getElementById("submit");
let output = document.getElementById("output");
const romanObject = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
XXX: 30,
XX: 20,
X: 10,
IX: 9,
V: 5,
IV: 4,
I: 1,
};
button.addEventListener("click", () => {
inputToRoman(input.value);
input.value = "";
});
function inputToRoman(num) {
let number = parseInt(num);
if (num.trim().length == 0) {
output.innerHTML = "Invalid Input";
return false;
}
if (number > 4999 || number < 1) {
output.innerHTML = "Input Out Of Range";
return false;
}
output.innerHTML = "";
let result = "";
let romanValues = Object.keys(romanObject);
romanValues.forEach((key) => {
while (romanObject[key] <= number) {
number -= romanObject[key];
result += key;
}
});
output.innerHTML = result;
}
</script>
</body>
</html>