Telephone checker code is working but failing test

Telephone checker code is working but failing test
0

#1

My code is working perfectly and passing all test conditions. However, I am getting this error:

TypeError: unknown: Cannot read property ‘0’ of undefined

Could you please help me identifying the issue?

My code is here: https://codepen.io/farooqumars/pen/vVVJQR


#2

Sounds like you are expecting something to be an array but in one or more test condition it is actually undefined.


#3

I am expecting that a string is provided for testing, not an array. But I convert that string to an array before parsing it.


#4

I suspect that the problem is at line no.60:
> if(isNaN(Number.isInteger(parseInt(str[i]))))

Still I am unable to find the issue


#5

You would get that error on that line if str is undefined.


#6

I removed these lines and it worked. Still not sure what was the cause but the problem is solved now.

for(var i=0; i<11; i++) 
    if(isNaN(Number.isInteger(parseInt(str[i]))))   // if str has any non-number char
        return false;