Problem with Roman Numerals Converter

I’m a bit stuck on the Roman Numeral Challenge.
This is the code I wrote, it seems to return the matching answers but its not passing the challenge. I’m still very new to Javascript and can’t quite figure out whats causing the issues. Any feedback would be greatly appreciated!

let romanNumerals = [ ]; (empty array)
function convertToRoman(num) {
const roman = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];

const numbers = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];

if (num <= 0) {
return romanNumerals.join('')
} else{
   let index = numbers.findIndex(function(number) {
   return number <= num;
})
romanNumerals.push(roman[index]);
convertToRoman(num - numbers[index]);
}

return romanNumerals.join('')
}

convertToRoman(3)

Challenge: Roman Numeral Converter

Link to the challenge:

Consider the implications of using global romanNumerals array for keeping result. You can wrap the function call at the bottom with the console.log(), to print out to console, what function returns. Add one or two more function calls and see what they return.

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