Build a Palindrome Checker

Guys, feel like I’m stuck here forever :sob:
Why my code doesn’t work and the console says “Uncaught TypeError: Cannot read properties of undefined (reading ‘match’)”?

I have even found the freeCodeCamp guide for building the Palindrome Checker

 const input = document.querySelector("#text-input");
const result = document.querySelector("#result");
const button = document.querySelector("#check-btn");
function isPalindrome() {
  const word = input.toLowerCase.match(/[a-z0-9]/g);
  if (input.value === "" || input === null) {
    alert("Please input a value");
    return false;
  } else if (word.join("") === word.reverse.join("")) {result.innerText = `${word} is a palindrome`;} else if (word.join("") !== word.reverse.join("")) {result.innerText = `${word} is not a palindrome`;}
};
button.addEventListener("click", isPalindrome);

Here’s where you wrote ‘match’. What’s right before it?

You mean parentheses () or str instead of input?

I don’t understand your question. What comes immediately before the letters m a t c h in the part of your code I quoted?

“toLowerCase.”, definitely :thinking: It is wrong?

Well, what is ‘toLowerCase’? Is that how you use that?

10000 thanks🙏 I’ve found the same mistake in reverse element. Looks like I have to read about chaining method one more time👍

1 Like