Build a Palindrome Checker Project - Build a Palindrome Checker

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

Hello, your close but you need a function first with an if statement and a return, right now you’ve kind of combined a click event with the if statement. So a function followed by the the other logic. I guess you could just rearrange things here but you still need a function for the input

input
<code>goes here</code>

One backtick for a single variable in a sentence.

Keep the triple backticks on a separate line

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

I ran into some problem with that, can you give me an example?

1 Like

Example above, and I’ve edited your post as well.

Triple backticks on a line by themself for a block of code. Single backticks around a single word to show it as code.

1 Like

Hi thanks for answering, but I found the real problem.
I put the script tag that contains the JS code in the head element before the button, instead I should’ve put it after button, at the end of my HTML.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.