Hi,
I am not sure why the code is not working. When I log out the required str, it works how it should, but the test aren’t passing.
const romanToArabic = {
//Testing 1 to 10 numerals
I : 1,
IV : 4,
V : 5,
IX: 9,
X: 10
}
let str = "";
function convertToRoman(num) {
let numeralWithLeastDifference;
for(let item in romanToArabic){
if(num === romanToArabic[item]){
str += item;
console.log(str)
return str
}
else if (num > romanToArabic[item]){
numeralWithLeastDifference = romanToArabic[item]
}
}
//console.log(numeralWithLeastDifference)
for (let item in romanToArabic){
if (numeralWithLeastDifference === romanToArabic[item]){
str+= item
num = num - numeralWithLeastDifference;
convertToRoman(num)
}
}
}
convertToRoman(8);
Link to the Problem- https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter
Thanks,
Deeti