Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TylerL-uxai/9ca5fa857275c5dd21d2 to your computer and use it in GitHub Desktop.
Save TylerL-uxai/9ca5fa857275c5dd21d2 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Roman Numeral Converter
// Bonfire: Roman Numeral Converter
// Author: @tylerl-uxai
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter
// Learn to Code at Free Code Camp (www.freecodecamp.com)
// re-wrote by myself with the aid of http://wulkan.me/bonfire-roman-numeral-converter/
function convert(num) {
var romanNumerals = '',
decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
numerals = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
for (var i= 0; i < decimals.length; i++){
while ( num >= decimals[i] ) {
romanNumerals += numerals[i];
num -= decimals[i];
}
}
return romanNumerals;
}
convert(36);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment