# Roman Numeral Converter arr.indexOf is not a function!?

Roman Numeral Converter arr.indexOf is not a function!?
0

#1

First off, I don’t want you to help me solve this puzzle. Please understand that I know this code is really bad and I suspect that this does not lead to a solution let alone a good solution.

PLEASE DO NOT HELP ME SOLVE THE CHALLENGE

I tried converting an array of strings to an array of numbers using `Number()`.

. For some reason when I do this FCC claims that `arr.indexOf` is not a function. What is this madness and why does it occur.

`arr.indexOf` is in the function assigned to arabicToRomanNumerals. I have left the comment “why?” above the line of code this is written in. Any advice on how to debug this in the future would be greatly appreciated.

Side note: What happened to the chatrooms we used to have?

My code so far

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

// roman numerals go 3 up and one down
var romanNumerals = ["M","D","C","L","X","V","I"];
var arabicNumerals = [9,8,7,6,5,4,3,2,1,0];
var numArr = Number(String(num).split(""));
var fourLong = function(arr){
if (arr.length < 4){
arr.splice(0,0,0);
fourLong(arr);
}};
fourLong(numArr);
var arabicToRomanNumerals = function(arr, num){
//why?
if(arr.indexOf(num) === 0){
return arr[0] * "M";
}
};

num = arabicToRomanNumerals(numArr, numArr[0]);

return numArr;
}

convertToRoman(1000);
``````

Your Browser User Agent is: `Chrome/60.0.3112.113 Safari/537.36`.

#2

After the following line executes:

``````var numArr = Number(String(num).split(""));
``````

your numArr variable is NaN and not an array. Inside the arabicToRomanNumerals function, you attempt to use the indexOf function with NaN and the indexOf function can only be used on arrays and strings.

When ever you are getting unexpected results, you can always throw in a console.log statement to check what a variable’s value is at any given point. If you put console.log(numArr) after the line I mentioned at the top, you can see the value is NaN.

#3

Thanks! I haven’t written any javascript for a while. I totally forgot about NaN