I have been working on this challenge for a day and I think the solution I came up with is correct. When I console.log and test it myself it is working well. However, when I try to submit it on FCC, it is not passing any of the tests. Don’t know what’s wrong with it!
My code
function convertToRoman(num) {
let romanArr = ['M' , 'CM' , 'D', 'CD', 'C' , 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
let decimalArr = [1000 , 900 , 500, 400 , 100, 90, 50, 40, 10, 9, 5, 4, 1];
let romanNum = " ";
for (let i = 0; i < romanArr.length; i++)
{
while(num >= decimalArr[i])
{
romanNum += romanArr[i];
num -= decimalArr[i];
}
}
return romanNum;
}
console.log(convertToRoman(5));