Tell us what’s happening:
I was having problem with variable definiton, and reading other threads on forum I found that it was a bug or someting with the tests.
So I use the variables that @ILM recomendeded in other post.
But now, the user storie 35 still not passing. Any sugestion?
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Telephone number Checker</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>
Telephone number <br />
Checker
</h1>
<section class="input-container">
<label for="number-input">Enter a telephone number:</label>
<input
id="user-input"
class="number-input"
/>
<button class="convert-btn" id="check-btn">Check</button>
</section>
<section class="output-container">
<h2>Check History</h2>
<div id="results-div"></div>
<button class="convert-btn" id="clear-btn">Clear</button>
</section>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
const userInput = document.getElementById("user-input")
const resultsDiv = document.getElementById("results-div")
const checkBtn = document.getElementById("check-btn")
const clearBtn = document.getElementById("clear-btn")
const check = () =>{
if(!userInput.value){
alert("Please provide a phone number")
return
}
//regular expressions for the valid phone number exemples
const validExemples = [/^\d{3}\-\d{3}\-\d{4}$/,
/^\(\d{3}\)\d{3}\-\d{4}$/,
/^\(\d{3}\)\s\d{3}\-\d{4}$/,
/^\(\d{3}\)\s\d{3}\s\d{4}$/,
/^\d{10}$/,
/^1\s\d{3}\s\d{3}\s\d{4}$/,
/^1\s\(\d{3}\)\s\d{3}\-\d{4}$/,
/^1\(\d{3}\)\d{3}\-\d{4}$/,
/^1\s\d{3}\-\d{3}\-\d{4}$/]
for (let exemple of validExemples){
if (exemple.test(userInput.value)){
addResult(`Valid US number: ${userInput.value}`)
userInput.value = ""
return
}
}
addResult(`Invalid US number: ${userInput.value}`)
userInput.value = ""
return
}
const addResult = (text) =>{
resultsDiv.innerHTML += `${text} <br>`
}
const clear = () =>{
resultsDiv.innerText = ""
}
clearBtn.addEventListener("click", clear)
checkBtn.addEventListener("click", check)
/* file: styles.css */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--light-grey: #f5f6f7;
--dark-blue: #1b1b32;
--orange: #f1be32;
}
body {
display: flex;
flex-direction: column;
align-items: center;
font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console,
monospace;
font-size: 1.125rem;
color: var(--light-grey);
background-color: var(--dark-blue);
padding: 0 4px;
}
h1 {
font-size: 2.125rem;
text-align: center;
margin: 20px 0;
}
h2 {
font-size: 1.5rem;
text-align: center;
margin: 20px 0;
}
.input-container {
display: flex;
flex-direction: column;
gap: 10px;
justify-content: center;
align-items: center;
width: clamp(320px, 50vw, 460px);
margin: 10px auto;
}
.input-container label {
white-space: nowrap;
word-spacing: -6px;
}
.convert-btn {
font-size: inherit;
font-family: inherit;
background-color: var(--orange);
width: 100%;
height: 2rem;
padding: 0 6px;
border: none;
border-radius: 2px;
cursor: pointer;
}
.number-input {
font-size: inherit;
padding: 0.3rem;
width: 100%;
}
.output-container {
margin-inline: auto;
width: clamp(320px, 50vw, 460px);
}
#results-div {
display: flex;
flex-direction: column-reverse;
justify-content: end;
gap: 1rem;
margin-block-end: 1rem;
min-height: 40vh;
border: 2px dashed var(--orange);
padding: 1rem;
}
@media screen and (min-width: 36em) {
body {
font-size: 1rem;
}
.input-container {
flex-direction: row;
width: unset;
}
.number-input {
width: unset;
}
}
The console output:
// running tests
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.
// tests completed
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Challenge Information:
Build a Telephone Number Validator Project - Build a Telephone Number Validator