diff --git a/roman_numerals.js b/roman_numerals.js index 8019de3..28383d4 100644 --- a/roman_numerals.js +++ b/roman_numerals.js @@ -1,5 +1,29 @@ function to_roman (num) { // your implementation code here + let output = '' + let roman = { + M: 1000, + CM: 900, + D: 500, + CD: 400, + C: 100, + XC: 90, + L: 50, + XL: 40, + X: 10, + IX: 9, + V: 5, + IV: 4, + I: 1 + } + + for (let key in roman) { + while (num >= roman[key]) { + output += key + num -= roman[key] + } + } + return output } // Drive code