So I’m doing some review and trying to write these problems out by hand on paper and when I console.log it seems to work but I keep getting an error for infinite loop and I just can’t see how. Could someone please point out what’s wrong here.
function convertToRoman(num) {
let result = '';
let rest = num;
let roman = {
'M': 1000,
'CM': 900,
'D': 500,
'CD': 400,
'C': 100,
'XC': 90,
'L': 50,
'XL':40,
'X': 10,
'IX': 9,
'V': 5,
'IV': 4,
'I': 1
}
for(let key in roman) {
while (rest > 0) {
if (rest >= roman[key]) {
result += key;
rest -= roman[key];
console.log(result);
}
}
}
return result;
}
convertToRoman(68);