I dont understand the while loop here. when num = 2, the decimalValue[0] = 1000. and the decimalValue[index] <=2 wont be satisfied. At least, its what i think. Please help
Your code so far
function convertToRoman(num) {
let decimalValue = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
let romanNumeral = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"];
let romanized = "";
for(let index = 0; index < decimalValue.length; index++)
{
while(decimalValue[index] <= num)
{
romanized += romanNumeral[index];
num-= decimalValue[index];
}
}
return romanized;
}
convertToRoman(36);
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; SM-A205YN) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.127 Mobile Safari/537.36
.
Challenge: Roman Numeral Converter
Link to the challenge: