Skip to content

Commit 34e1186

Browse files
committed
added the code
1 parent 0769f57 commit 34e1186

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Roman_Numeral_Converter/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function convertToRoman(num) {
2+
// get the variables of each roman numerals first
3+
let romanNumerals = {
4+
M: 1000,
5+
CM: 900,
6+
D: 500,
7+
CD: 400,
8+
C: 100,
9+
XC: 90,
10+
L: 50,
11+
XL: 40,
12+
X: 10,
13+
IX: 9,
14+
V: 5,
15+
IV: 4,
16+
I: 1,
17+
}
18+
let total = ""
19+
// run a for loop for each numeral in the roman numerals
20+
for (let numeral in romanNumerals) {
21+
// run a while loop for num(36)
22+
while (num >= romanNumerals[numeral]) {
23+
// total will combine each letter
24+
total += numeral;
25+
// num will decrement to stop the loop
26+
num -= romanNumerals[numeral];
27+
}
28+
}
29+
return total;
30+
}
31+
32+
console.log(convertToRoman(36));

0 commit comments

Comments
 (0)