hi all!
so i solved the challenge with this horrible code, and i don’t know how to make it better.
also, this code can’t really convert numbers more than 3999, unless i hard coded it in both the arrays.
what am i missing please, i want to get better.
this is my code
var romanNums = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M", "MM", "MMM"];
var arabic = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "2000", "3000"];
function convertToRoman(num) {
var result = [] ;
var display = "";
//separate the number and add them into an array
var numToArray = num.toString().split("").map(Number);
for (var i = 0; i < numToArray.length ; i++) {
var inte = numToArray[i];
//keep counting of the zeros added to the integer.
var addZero = inte;
//add zero everytime it loops
for (var j = 0; j < numToArray.length - i-1; j++) {
addZero += "0";
};
//addZero stored in an array and transformed all into integers
result.push(parseInt(addZero));
for (var d = 0; d < arabic.length; d++) {
//find the match and add the romanNumbers next to each other
if(result[i] == arabic[d]){
display += romanNums[d];
}
}
};
console.log(display);
}
convertToRoman(3000);