Tests are failing but console is printing them correctly

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

The code says it fail converstion tests, but by console they are printed correctly.

image

   **Your code so far**

const romanNumbers = {
 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"
}

function convertToRoman(num) {
 let number = num;
 let romansArr = Object.entries(romanNumbers);
 let romanNumber = "";
 for(let i = romansArr.length-1; i >= 0 ; i--) {
   while(number  >= romansArr[i][0])
   {
     
     romanNumber+=romansArr[i][1];
     number -=romansArr[i][0];
    
   }
    
 }
console.log(romanNumber, num);
return romanNumber.toUpperCase();
}

convertToRoman(4);
convertToRoman(44);
convertToRoman(1004);
convertToRoman(2014);
   **Your browser information:**

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

Challenge: Roman Numeral Converter

Link to the challenge:

I would sort that array. The order is not guaranteed, which may cause confusing results.

I would make sure you don’t have any extraneous white space in your romanNumbers object.

Good eyes!

Should still check the order since you will get different results on different browsers though!

1 Like

Ya, or maybe use a Map instead.

1 Like

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