Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

Hello, please help. I wrote all the code needed but it still won’t run, maybe I’m missing something. Please help.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Palindrome Checker</title>
    </head>
    <body>
        <h1>Is it a Palindrome?</h1> 
          <input id="text-input">
      <button id="check-btn">Check</button>
      <div id="result"></div>
      <script src="script.js"></script>
        </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", ()=>{
    const lowerReplaced = textInput.value.toLowerCase().replace(/[^a-z0-9]/g,"")


    if(textInput.value === "") {
      alert("Please input a value")
    } else if(textInput.value.length === 1) {
      result.innerText = `${textInput.value} is a palindrome`
    } else if (lowerReplaced === [...lowerReplaced].reverse().join("")) {
      result.innerText = `${textInput.value} is not a palindrome`
    }
});
    

    
/* file: styles.css */


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

can you describe what this is doing for me?

this is for when a specific word is not a palindrome

Try using console.log() on the inputs before it goes into the if statement

console.log(lowerReplaced)
console.log([...lowerReplaced].reverse().join(""))

Confirm what you are comparing

Like this?

console.log(lowerReplaced);
console.log([…lowerReplaced].reverse().join(“”));
if(textInput.value === “”) {
alert(“Please input a value”)
} else if(textInput.value.length === 1) {
result.innerText = ${textInput.value} is a palindrome
} else if (lowerReplaced === […lowerReplaced].reverse().join(“”)) {
result.innerText = ${textInput.value} is not a palindrome
}
});

can you define a palindrome?

no, I tried. I cannot define a palindrome

what did you try? did you look up on the internet? what part of the palindrome definition is giving you issues?

Look at the example project. The definition of a palindrome is right there.

wait no sorry I can define a palindrome lol. I thought you were asking whether the website that I built can detect a palindrome

My code is not running. May you please help me detect the problem. I think I’m missing something

can you tell me what is a palindrome?

a word that is spelt and pronounced the same when you read it from right to left and from left to right

would you say that this is what’s being checked here?

no, I don’t think so…?

then what’s that line of code doing?

It checks if the word is a palindrome or not. I think I may have written it wrong because it doesn’t work on my side

when do you expect that to return true, when it is a palindrome or when it is not a palindrome?

when it is a palindrome

then why are you writing that it is not a palindrome in the next line?