I can't solve steps 7-12 in the telephone validator project

const userInput = document.getElementById("user-input");
const checkBtn = document.getElementById("check-btn");
const clearBtn = document.getElementById("clear-btn");
const resultDiv = document.getElementById("results-div");

checkBtn.addEventListener("click", () => {
  if (userInput.value === "") {
    alert("Please provide a phone number");
  } else {
    const teleRegex = /^(1\s?)?[(\d)]{3}?(-\s)[\d]{3}(-\s)?[\d]{3}(-\s)?[\d]{4}/
    if (teleRegex.test(userInput.value)) {
      resultDiv.textContent = `Valid US number: ${userInput.value}`
    } else {
      resultDiv.textContent = `Invalid US number: ${userInput.value}`
    }
  }
})

clearBtn.addEventListener("click", () => {
  resultDiv.textContent = "";
})

I am unable to pass steps 7-12, I would be grateful if you explain what I am doing wrong.

Thank you for your time!

Focus on one at a time.

Do you mean User Story 7 or Test 7?

What have you tried so far?

How does your result differ?

I failed test 7-12, and I haven’t looked at solutions

What have you tried so far for test 7?

How does your result differ from the requirements of test 7?

Here are some troubleshooting steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the first failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

Thanks man there was a problem with my regex

1 Like