A Pen by Dano Manion on CodePen.
Created
March 14, 2018 00:20
-
-
Save danomanion/823a986092b6886d7711748fc8d4067b to your computer and use it in GitHub Desktop.
JavaScript - JS String Roman Numerals Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.freecodecamp.org/challenges/roman-numeral-converter | |
function convertToRoman(num) { | |
var romanNumeral = ["M", "CM","D", "CD", "C","XC","L","XL","X","IX","V","IV","I"], | |
latinNumbers = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], | |
romanTxt = ""; | |
for (var i = 0; i < latinNumbers.length; i++) { | |
while(num >= latinNumbers[i]) { | |
romanTxt += romanNumeral[i]; | |
num -= latinNumbers[i]; | |
} | |
} | |
return romanTxt; | |
} | |
console.log(convertToRoman(3600)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment