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