Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I seem to be the only one having a problem with the .split(“”) part of my code. For days I’ve tried seeing what the issue could be that the console keeps saying filtered.split is not a function. Today I decided to check other queries but none is like mine. What am I doing wrong?

Your code so far

<!-- file: index.html -->

/* file: script.js */
return filtered === filtered.split("").reverse().join("") 
? resultSlot.innerHTML = `${input.value} is a palindrome`
: resultSlot.innerHTML = `${input.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/126.0.0.0 Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

you’ve only shown us a snippet of your code.
What is filtered supposed to be?

Uncaught TypeError: filtered.split is not a function
This is the error being shown.

const checkBtn = document.querySelector(“#check-btn”);
const resultSlot = document.querySelector(“#result”);
const input = document.querySelector(“#text-input”);

checkBtn.addEventListener(“click”, () => {

if (input.value === “”) {
alert(“Please input a value”);
};

const isPalindrome = () => {

const trimmed = input.value.trim();
const lower = trimmed.toLowerCase();
const filtered = lower.match(/[a-z0-9_]/g);

return filtered === filtered.split(“”).reverse().join(“”)
? resultSlot.innerHTML = ${input.value} is a palindrome
: resultSlot.innerHTML = ${input.value} is not a palindrome

};

thanks. Did you figure out what filtered is yet?

Yeah, filtered is the ultimate resulting string after trimming, converting to lower case and matching the characters using the regex. I just don’t understand the error when I try to ‘split’ it

Ooh wait, I’ve seen the issue, let me rectify and get back to you

1 Like

Yes! I’ve replaced match with the right method (pun intended). Thank you.

1 Like