Forked from anonymous/bonfire-roman-numeral-converter.js
Created
December 10, 2015 15:35
-
-
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
This file contains hidden or 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
// 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