We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0769f57 commit 34e1186Copy full SHA for 34e1186
Roman_Numeral_Converter/script.js
@@ -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