Tell us what’s happening:
Everything is correct. Everything is working but the tests say the results don’t show? But they do show
pls help
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">
<title>Phone Number Validator</title>
<style>
* {
box-sizing: border-box;
background-color: #2e3440;
color: snow;
}
body {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
width: 25%;
margin: 10px auto;
}
#header {
color: orangered;
font-size: 2rem;
margin: 40px 0;
}
.text, .btn {
width: 100%;
}
.btn {
height: 2rem;
padding: 0 6px;
margin: 4px;
border: none;
border-radius: 2px;
cursor: pointer;
background-color: snow;
color: #2e3440;
}
#results-div {
padding: 10px;
width: 100%;
margin-top: 20px;
border: 1px solid snow;
min-height: 50px;
}
</style>
</head>
<body>
<div id="header">Phone Number Validator</div>
<input class="text" id="user-input" />
<button class="btn" id="check-btn">Check</button>
<button class="btn" id="clear-btn">Clear</button>
<div id="results-div"></div>
<script>
const userInput = document.getElementById("user-input");
const result = document.getElementById("results-div");
document.getElementById("check-btn").addEventListener("click", () => {
const input = userInput.value;
if (!input) {
alert("Please provide a phone number");
} else {
const regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/;
result.textContent = regex.test(input) ? `Valid US number: ${input}` : `Invalid US number: ${input}`;
}
});
document.getElementById("clear-btn").addEventListener("click", () => {
userInput.value = "";
result.textContent = "";
});
</script>
</body>
</html>
/* file: script.js */
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0
Challenge Information:
Build a Telephone Number Validator Project - Build a Telephone Number Validator