I’m sure there easier and more efficient ways to do this challenge, but I would like to know how I messed up my way! So why isn’t this way giving me any results for hundR? The console returns nothing.
function convertToRoman(num) {
var arr = [];
//convert number to string to array
num = num + "";
arr = num.split("");
//split number into groups
var thou = (arr[arr.length - arr.length]);
var hund = (arr[arr.length - (arr.length-1)]);
var tens = (arr[arr.length - (arr.length-2)]);
var ones = (arr[arr.length - (arr.length-3)]);
//changes groups into roman
//thousands
var thouR = "";
for (var i = 0; i < thou ; i++){
thouR += "M";
}
//hundreds
var hundR = "";
switch (hund){
case 0:
case 1:
case 2:
case 3:
for (var j = 0; j < hund ; j++){
hundR += "C";
}
break;
case 4:
hundR = "CD";
break;
case 5:
case 6:
case 7:
case 8:
hundR = "D";
for (var k = 5; k < hund ; k++){
hundR += "C";
}
break;
case 9:
hundR = "CM";
break;
}
return hundR;
}
convertToRoman(3399);