So I tried a recursion solution to the roman numeral converter problem. Any number that i test by console logging the function returns what I want. However the “running the tests” says that none of them pass. Does anybody know why? I’m aware this is not the most efficient solution but shouldn’t it still work?
let newNum = '';
function convertToRoman(num) {
if (num < 1) {
return newNum
} else if (num >= 1000) {
newNum += 'M';
return convertToRoman(num-1000);
} else if (num >= 900) {
newNum += 'CM';
return convertToRoman(num-900);
} else if (num >= 500) {
newNum += 'D';
return convertToRoman(num-500);
} else if (num >= 400) {
newNum += 'CD';
return convertToRoman(num-400);
} else if (num >= 100) {
newNum += 'C';
return convertToRoman(num-100);
} else if (num >= 90) {
newNum += 'XC';
return convertToRoman(num-90);
} else if (num >= 50) {
newNum += 'L';
return convertToRoman(num-50);
} else if (num >= 40) {
newNum += 'XL';
return convertToRoman(num-40);
} else if (num >= 10) {
newNum += 'X';
return convertToRoman(num-10);
} else if (num >= 9) {
newNum += 'IX';
return convertToRoman(num-9);
} else if (num >= 5) {
newNum += 'V';
return convertToRoman(num-5);
} else if (num >= 4) {
newNum += 'IV';
return convertToRoman(num-4);
} else if (num >= 3) {
newNum += 'III';
return convertToRoman(num-3);
} else if (num >= 2) {
newNum += 'II';
return convertToRoman(num-2);
} else if (num >= 1) {
newNum += 'I';
return convertToRoman(num-1);
}
return newNum;
}