Build a Palindrome Checker

Please, help me! why my alert doesn’t work and why I have a message in the console saying “input.includes is not a function”?

const input = document.querySelector("#text-input");
const result = document.querySelector("#result");
const button = document.querySelector("#check-btn");
const userInput = () => {
  if (input === "" || input === null) {
    alert("Please input a value");
    return false;
  } else if (input.value === "A") {
    result.innerText = ("A is a palindrome"); 
  } else if (input.includes("eye")) {
    result.innerText = "eye is a palindrome";
  } else if (input.includes("_eye")) {
      result.innerText = ("_eye is a palindrome");
    } else if (input.includes("race car")) {
      result.innerText = "race car is a palindrome";
    }
};
button.addEventListener("click", userInput);

Hi @JackLantern

  1. my alert doesn’t work

You need to access the value of the input element.

e.g.

  1. why I have a message in the console saying “input.includes is not a function”?

You are using the .includes method, which is used on arrays, so won’t work here.

  1. You are hard coding the solutions. You need to create an app which can take any valid input from the user, and determine whether it is or is not a palindrome.

Happy coding

1 Like