Roman Numeral Converter runs perfectly in chrome console but not in FCC

I don’t know why this code is running in my chrome console but its not passing the freecodecamp challenge. Like none of the tests passed.


function convertToRoman(num){
  let baseRomNumerals=["M","XM","D","XD","C","XC","L","XL","X","IX","VIII","VII","VI","V","IV","III","II","I"];
  let baseDecNumerals=[1000,900,500,400,100,90,50,40,10,9,8,7,6,5,4,3,2,1];
  let romanNumeral="";
  for(let i=0;num>0&&i<baseDecNumerals.length;i++){
    if(num>=baseDecNumerals[i]){
      romanNumeral+=baseRomNumerals[i];
      num-=baseDecNumerals[i];
      while(num>=baseDecNumerals[i]){
      romanNumeral+=baseRomNumerals[i];
      num-=baseDecNumerals[i];

    }
    }
  } 
}
convertToRoman(2);

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter

You should return romanNumeral; somewhere. :slight_smile:

1 Like