Tell us what’s happening:
I’m working on Telephone Number Validator challenge and what I’m trying to do is to get the Boolean return true when the phone number is equal to 10 digits and if the phone number is equal to 11 digits and the first digit starts with number 1, also return true. Otherwise return false.
Instead, what I’m getting is they all return false, totally ignoring my conditional statements. I’m positive that the logical steps should be correct, but how I implement it is probably not the right way.
Your code so far
function telephoneCheck(str) {
if (str.length === 10) {
return true
} else if (str.length === 11 && str[0] === '1') {
return true
} else {
return false
}
}
// should return false
// has letters (a-z)
console.log(telephoneCheck("123**&!!asdf#"))
// less than 10 numbers
console.log(telephoneCheck("555-5555"))
// not no.1 at the start
console.log(telephoneCheck("2 (757) 622-7382"))
// should return true
console.log(telephoneCheck("555-555-5555"));
console.log(telephoneCheck("1 (555) 555-5555"))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Telephone Number Validator
Link to the challenge: