Tell us what’s happening:
My code is not producing the desired output for number 4 and numbers greater than 4.
Your code so far
function convertToRoman(num) {
let numerals = {
1000: "M",
900: "CM",
500: "D",
400: "CD",
100: "C",
90: "XC",
50: "L",
40: "XL",
10: "X",
9: "IX",
5: "V",
4: "IV",
1: "I"
};
let roman = "";
let decimal = Object.keys(numerals);
decimal.forEach(key => {
while(key <= num){
roman += numerals[key];
num -= key;
};
});
return roman; // Return the Roman numeral string
};
convertToRoman(4);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter