Need help with property error (Roman Numeral Converter)

I don’t understand why I am getting a “TypeError: Cannot read property ‘1’ of undefined” error. What is the error and how do I fix it?

Code:

> function convertToRoman(num) {
> 
>     let numbers = [
> 
>       ['M', 1000],
> 
>       ['CM', 900],
> 
>       ['D', 500],
> 
>       ['CD', 400],
> 
>       ['C', 100]
> 
>       ['XC', 90],
> 
>       ['L', 50],
> 
>       ['XL', 40],
> 
>       ['X', 10],
> 
>       ['IX', 9],
> 
>       ['V', 5],
> 
>       ['IV', 4],
> 
>       ['I', 1]
> 
>     ]; 
> 
>   
> 
>   for (let count = 0; count < numbers.length; count++){
> 
>     if(num >= numbers[count][1]){
> 
>       return numbers[count][0] + convertToRoman(num - numbers[count][1]);
> 
>     }
> 
>   }
> 
>   }
> 
>   
> 
>   convertToRoman(36);

Hey @deep_singh, not sure why there are greater than signs at the beginning of every line of your code but you should not do that as it makes it harder for other people to clean up your code in order to test it.

Take a look at your numbers array very closely. One of them is missing a comma.

1 Like

Oh, I see. Those aren’t greater than signs, I think those represent a new line. When posting, I clicked the </> sign thinking it was for adding code, and it did that.

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