I'm stuck with the roman numeral converter

Roman numeral converter not working
Most of the test has passed but some don’t. Any thoughts and help is appreciated. :wink:

var romanNumerals = [['','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']];


function convertToRoman(num) {
  var romanian = '';
  var numbers = num.toString().split('').reverse();
  for (var i=0; i < numbers.length; i++) {
    romanian = romanNumerals[i][parseInt(numbers[i])] + romanian;
  }
 return romanian;
}

convertToRoman(36);

var romanNumerals = [['','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']];


function convertToRoman(num) {
 var romanian = '';
 var numbers = num.toString().split('').reverse();
 for (var i=0; i < numbers.length; i++) {
   romanian = romanNumerals[i][parseInt(numbers[i])] + romanian;
 }
return romanian;
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36

Challenge: Roman Numeral Converter

Link to the challenge:

Which tests aren’t passing?

This can’t be helping.

And it looks like you’re missing the 1000s digit.

1 Like

convertToRoman(4) should return the string IV .
convertToRoman(44) should return the string XLIV .

convertToRoman(1000) should return the string M

convertToRoman(1004) should return the string MIV

convertToRoman(1006) should return the string MVI

convertToRoman(1023) should return the string MXXIII

convertToRoman(2014) should return the string MMXIV

convertToRoman(3999) should return the string MMMCMXCIX

All these are not passing.

How are you handling the 1000s digit? I don’t see it in your code.

1 Like

Thank you, I’ve added the 1000s digit and removed the extra comma. I’m still getting the last six errors and my brain is now fried. Lol.

How did you add the last digit?

1 Like

[[’’,‘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’]];

Like so?!

1s digit:

[’’,‘I’,‘II’,‘III’,‘IV’,‘V’,‘VI’,‘VII’,‘VIII’,‘IX’]

10s digit:

[’’,‘X’,‘XX’,‘XXX’,‘XL’,‘L’,‘LX’,‘LXX’,‘LXXX’,‘XC’]

100s digit:

[’’,‘C’,‘CC’,‘CCC’,‘CD’,‘D’,‘DC’,‘DCC’,‘DCCC’,‘CM’,‘M’]

I don’t see anything that handles the 1000s digit in here at all? Did you copy the wrong thing?

1 Like

Possibly. :upside_down_face:
I think I need to add one more line there.

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