Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danomanion/823a986092b6886d7711748fc8d4067b to your computer and use it in GitHub Desktop.
Save danomanion/823a986092b6886d7711748fc8d4067b to your computer and use it in GitHub Desktop.
JavaScript - JS String Roman Numerals Program
// 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