Telephone Number Validator test code wont work

so ive tried to debug this code in FCC and in Repl.it to try and understand what is happening. when running the code manually it works but for some reason with FCCs test code it does not work. pleas help me


function telephoneCheck(str) {
 let strArr = str.split(/[\D]/g);
 console.log(strArr);
 let lenght = 0;
for(let i = 0; i<strArr.length;i++){
   length += strArr[i].length;
 }
console.log(length);
console.log(str.charAt(0));
if("1"==str.charAt(0)){
  console.log("11 digits");
  return (11 == length);
}
else{
  console.log("10 digits");
  return (10 == length);
}
return false;

}

telephoneCheck("555-5555")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator

1 Like

You spelled length wrong

What @JohnKalinauskas said, but also I think it’s not quite as simple as what you’re doing: so for example, the test for (555)5(55?)-5555") should return false. But if you remove all the non-digits, you get 5555555555, which is valid

1 Like