JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

Tell us what’s happening:
Describe your issue in detail here.

I’m getting the correct answer in console but it doesn’t pass the test. why so?

Your code so far

function convertToRoman(num) {
 const map = {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};

   let result = " ";   
   
   for(let key in map){
       let numeral = Math.floor(num / map[key]);

     if(numeral !== 0){
       result = result + key.repeat(numeral);
     }
     num %= map[key];

     if(num === 0) return result;
   }


    return result;
}

convertToRoman(36);
console.log(convertToRoman(3999));

Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

Link to the challenge:

Try making this equal to "" with no space between

Edit: I noticed your strings start with a space so you will need to trim the space before returning

I did this and it passed the test… thank you

1 Like