Build a Telephone Number Validator Project - errors in test module?

Tell us what’s happening:

I’m doing the JS Algorithms and Data Structures certification (again as it was remade…) and, on the telephone number validator certification project, I encounter errors in the test module (I suppose) that prevent me from completing it.

I get the [ReferenceError: Can't find variable: resultsDiv] although, as you may notice, I don’t use such variable name in my code. Every test passes except the last 2, which are composed of hidden tests I suppose and which rely on the resultsDiv variable…

35. When the #user-input element contains a valid US number and the #check-btn element is clicked, the #results-div element should contain the text "Valid US number: " followed by the number.
36. When the #user-input element contains an invalid US number and the #check-btn element is clicked, the #results-div element should contain the text "Invalid US number: " followed by the number.
// tests completed
// console output
[ReferenceError: Can't find variable: resultsDiv]
[ReferenceError: Can't find variable: resultsDiv]

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Palindrome Checker</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <input id="user-input"></input>
    <button id="check-btn">Check</button>
    <button id="clear-btn">Clear</button>
    <div id="results-div"></div>
    <script src="script.js"></script>
</body>
</html>
/* file: script.js */
function telephoneCheck(str) {
  //logic here - redacted to help others learn
  return res
}

document.getElementById("clear-btn").addEventListener("click", ()=>{document.getElementById("user-input").value="";document.getElementById("results-div").textContent=""})

document.getElementById("check-btn").addEventListener("click", () => {
    const input = document.getElementById("user-input").value;
    if (!input) {
        alert("Please provide a phone number");
    } else {
        document.getElementById("results-div").textContent = telephoneCheck(input) ? `Valid US number: ${input}` : `Invalid US number: ${input}`;
    }
});

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15

Challenge Information:

Build a Telephone Number Validator Project - Build a Telephone Number Validator

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

there is a bug in the tests, you need to use these variables (and they need to go in the global scope)

1 Like

Thanks. That worked! Hope that’ll get fixed soon. :slight_smile:

1 Like

Fix is in the works. :+1:

1 Like