This is about one of the evaluation tests, so I don’t want much help, but I am not sure if I can call a function from an if statement nested in a for loop and do a return that breaks me out of the global function that I am in or if the return just breaks me from the for and/or if. Basically, I am asking if return treats either an if or a for as a function which would mean I am only breaking from a subfunction and not the one I really want to break from. I don’t think I should get more help than this clarification on the return functionality in this situation.
**Your code so far**
function telephoneCheck(str) {
let digits=str.replace(/\D/g, '');
let length=digits.length;
let newStr="";
let patterns=[/[^\(\)-\s\d]/g, /\(^\d{3}^\)/g];
let passfail=true
if (digits[0]=="1" && length==11) {
newStr=str;
} else if (digits[0]!="1" && length==10) {
newStr="1 "+str;
} else {
return false;
}
console.log(newStr, patterns[0].test(newStr), patterns[1].test(newStr));
for (let i=0; i<patterns.length; i++) {
if (patternTest(newStr, patterns[i])){
return false;
}
}
//It seems that I have eliminated all types of falses that matter.
return true;
function patternTest(s,p) {
return p.test(s)
}
}
telephoneCheck("(555)5(55?)-5555");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Telephone Number Validator
Link to the challenge: