# Roman Numeral Converter - Stuck on error [solved]

Hi!

I have the following error: undefined is not an object (evaluating ‘arr1[i]’)
, but can’t figure out where the problem in my code is…

Here is my code:

``````function convertToRoman(num) {

var arr1 = [[1000,"M"],[500,"D"],[100,"C"],[50,"L"],[10,"X"],[5,"V"],[1,"I"]];
var arr2 = [];

for (var i=0; i= arr1.length; i++) {

if (arr1[i] < num) {
num -= arr1[i];
arr2.unshift(arr1[i]);
} else if ( num = 1) {
return "I";
} else { return "0" ;
}
}
return arr2.joint('');
}

``````

you have a weird conditional ‘i = arr1.length’

which is not a conditional at all as you are assigning the length of arr1 to i

I think you meant to write
i < arr1.length ?

1 Like

Just noticed a couple of other errors, thanks!

Managed to fix the bugs ``````function convertToRoman(num) {

var arr1 = [[1000,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[5,"V"],[4,"IV"],[1,"I"]];
var arr2 = [];

for (var i=0; i < arr1.length ; i++) {

while (num > arr1[i]) {
num -= arr1[i];
arr2.push(arr1[i]);
}

if (num === arr1[i]) {
arr2.push(arr1[i]);
return arr2.join("")
}
}
}
``````