Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I can’t get my function to print ${textInput.value} is not a plaindrome it only prints is a plaindrome

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="eng">

<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>Palindrome Checker</title>
  <link rel="stylesheet" href="styles.css">
</head>

<body>
  <main class="container">
    <h1 class="title">Is it a plaindrome?</h1>
    <div class="palindrome-form">
      <input id="text-input" value-type="text"/>
      <button id="check-btn" type="submit">Check</button>
      <div id="result" class="hide"></div>
    </div>
  </main>
  <script src="./script.js"></script>
</body>

</html>
/* file: script.js */
const textInput = document.getElementById("text-input");
const checkBtn = document.getElementById("check-btn");
const result = document.getElementById("result");

function validateInput () {
  if (textInput.value === "") {
  return alert("Please input a value");
  } else if (textInput.value === textInput.value.split().reverse().join()) {
    return result.innerHTML = `${textInput.value} is a palindrome`;
  } else {
    return result.innerHTML = `${textInput.value} is not a palindrome`;
  }
};

checkBtn.addEventListener("click", () => {
  validateInput(textInput.value);
});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) 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

I think you should print out each stage of

textInput.value.split().reverse().join().

It’s quite difficult to just chain several functions together like this without verifying each before adding the next. textInput.value.split() might not return what you are expecting.

keep in mind that reverse will reverse in place, so if the value you are trying to reverse is a const, it will not work (you need a copy of the value first)
also join() puts commas in between whatever it joins, you have to use ‘’ to make it join with no spaces
split() also needs a param in order to split the string into its characters (use ‘’)

I am stuck with what you are saying here
I am not sure wy it is not working still

Did you try to log your code to see if it is doing what you thought? (This was the first suggestion given above by someone).

If you did and you don’t like the log result, the next step is to lookup each chained function to see if you are using it correctly.

If you are still stuck, share your more recent code so we can take another look (assuming you have made fixes and added some logs at least)