Please help me.! I can not.!

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function telephoneCheck(str) {

let newStr = str;
if (newStr[0] === "(" || newStr[0] === "-") {
  return false;
}
newStr = newStr.replace(/\s/g, "");
newStr = newStr.replace(/\-/g, "");

let backed = [];

for (let i = 0; i < newStr.length; i++) {
  if(newStr[i] === "(" || newStr[i] === ")"){
    backed.push(newStr[i])
    newStr = newStr.replace(newStr[i], "")
  }
  else if (isNaN(parseInt(newStr[i]))) {
    return false;
  }
}

console.log(newStr, backed)

if (backed.length % 2 !== 0) {
  return false;
}

if (newStr.length == 10 ) {
  return true;
} else if (newStr.length == 11 && newStr[0] == 1) {
  return true;
} 

return false;


}

console.log(telephoneCheck("(6054756961)"));
  **Your browser information:**

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

Challenge: Telephone Number Validator

Link to the challenge:

What is your question? With what are you having troubles? What have you tried already?

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.