Tell us what’s happening:
I don’t understand why my code is not working.
I am trying to throw an alert when there is no text input.
What is wrong with my code?
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">
<script src="index.js"></script>
</head>
<body>
<main>
<header>
<img
class="logo"
src="https://cdn.pixabay.com/photo/2014/04/02/11/01/fire-305227_1280.png"
alt="fire logo"
height="70"
width="auto">
<h1>Is this a Palindrome?</h1>
</header>
<div class="checker-div">
<label for="text-input">Enter in text to check for a palindrome:</label>
<input type="text" id="text-input">
<button type="submit" class="check-btn" id="check-btn">Check</button>
<div class="results-div hidden" id="result"></div>
</div>
<div class="info-div">
<p><img
src="https://cdn.pixabay.com/photo/2017/01/31/21/23/filament-2027372_1280.png"
alt="Light Bulb"
height="20"
width="auto"> A <i>palindrome</i> is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
</div>
</main>
</body>
</html>
/* file: script.js */
const textInput = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const result = document.getElementById("result");
checkButton.addEventListener("click", () => {
if(textInput.value === ""){
alert("Please input a value")
}
});
/* file: styles.css */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: black;
}
main {
width: 100%;
min-height: 100vh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.logo{
height: 40px;
margin-bottom: 20px;
margin-left: 40%
}
h1 {
color: white;
text-align: center;
padding: 10px 0;
font-size: 2.5rem;
margin-bottom: 10px;
}
.checker-div {
background-color: white;
width: min(100vw, 450px);
min-height: 100px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 10px;
margin: 10px;
}
label{
margin-bottom:20px;
}
input{
height: 30px;
width: 200px;
text-align: center;
font-size: 1.8rem;
border: none;
border-bottom: 2px solid;
margin: 10px;
}
.check-btn{
width: 90px;
border: none;
padding: 10px;
margin-bottom: 10px;
border-radius: 40px;
color: red;
background-color: black;
font-size: 1.2rem;
font-weight: bold;
cursor: pointer;
}
.info-div {
width: width: min(100vw, 450px);
min-heigt:100px;
padding: 10px;
margin: 10px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
background-image: linear-gradient(to top, #ff6e6e, #fd846d, #fa9770, #f5a979, #f1ba87, #f1c58e, #f2cf96, #f2d9a0, #f5e2a2, #f6eba4, #f6f4a7, #f5feab);
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker