Question 9 of Build a Palindrome Checker Project

  1. When the #text-input element contains the text not a palindrome and the #check-btn element is clicked, the #result element should contain the text "not a palindrome is not a palindrome"

My code so far:

const textInput = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const result = document.getElementById("result");

checkButton.addEventListener("click", () => {
  const replaced = textInput.value.replace(/[A-Za-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 (replaced === [...replaced].reverse().join("")) {
    result.innerText = `${textInput.value} is a palindrome`
  } else {
    result.innerText = `${textInput.value} is not a palindrome`
  }
});

I have researched, checked on Youtube, and stared at it for hours, but still cannot figure out why my code doesn’t pass. It just keeps repeating the same user story when I run it . Can anyone see what I am missing?

what do you want to remove from your string?

Are you asking me to edit the code?

no, I am asking you to write a sentence that describes which characters you want to remove from your string

Okay, I am not sure I understand, but I believe I am to define what is not a palindrome for the last else statement, which my code does, but it still doesn’t pass.
I really appreciate your quick response, and am eager to figure this out, but I have an important appointment and have to leave for a couple of hours. Will check back in when I return. Thank you.

ok, let’s try again.

The input can have any characters, like "@:)-(€/&;€3/&;€/€!o3&;€:!", which characters do you remove or which do you keep to test if the string is a palindrome or not?

this is important to get to the point of where your issue is

Apologies, I am sitting here rereading your question over and over and I am still so lost. I have no idea.

that’s an issue, the project specifically asks to keep only a certain set of characters when checking if a string is a palindrome. I would say, try reading again the instructions until you find that part.

I reread the instructions as you suggested. This is the part that I believe you are referring to:

Note: You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.

And the part of my code that isn’t passing

} else {
result.innerText = ${textInput.value} is not a palindrome
}

What isn’t needed for this to work? I don’t see anything that would cause an error, it isn’t different than the code I wrote above, except for the word ‘not’. That is all I changed or this step. Why would that throw an error?

So if you remove all non-alphanumeric characters from this string, what does remain?

check your replaced value when you enter this string in your app, does it match what you expect?