Roman Numeral converter - any tips?

Hi All,

could someone please provide me with some hints for the following code,

I was hoping the while loop would work, however, it’s not completing the challenge, and I hope some fresh eyes will be able to see something I can’t,

Many Thanks

   **Your code so far**

function convertToRoman(num)
//Roman Numeral values
{let romanNum = {
 M: 1000,
 CM: 900,
 D: 500,
 CD: 400,
 C: 100,
 XC: 90,
 L: 50,
 XL: 40,
 X: 10,
 IX: 9,
 V: 5,
 IV: 4,
 III: 3,
 II: 2,
 I: 1
};
// Variable to allow the keys to get moved into.
let converted = '';

// While loop to see if the num value is greater than said key before moving through rest of keys, and adding to converted variable. 
for (let key in romanNum) {
 const number = romanNum[key];
 while (number <= num) 
       {num -= number;
       converted =+ key;
         }
}
return converted;
}

convertToRoman(36);
   **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

Challenge: Roman Numeral Converter

Link to the challenge:

hmmm what would =+ do?

3 Likes

When I did this challenge, I set my object up differently. It was numbers to the roman numerals and grouped them by ones, tens, hundreds ie
{ ones: { 1: I
…9:IX},
tens: { 2: XX,
3: XXX,
4: XL,
…9: XC,
hundreds:…}
but that was just me as the roman numerals did not behave in a pattern, Also, you will not have to consider 0s.

Hey, thanks for the tip! saw it, changed it and it worked.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.