Build a palindrome checker

hi can anybody give me advice on how to complete this project I tried to build a function that iterates through the string below and returns the resullt i also added a if statement that states if str !=== i return “is not a palindrome” i think im missing something any advice?

const textInput = document.getElementById(“text-input”);

const checkButton = document.getElementById(“check-btn”);

const result = document.getElementById(“result”);

const str = /[^A-Za-z0-9_.]/.match().join().reverse();
for (let i = 0; i < str.length; i++)
return result;
if (str !== i) {
return “is not a palindrome”

}

checkButton.addEventListener(“check-btn”,)

first issue: match is a string method, and receives a regex as argument. Also, you would need to use the g flag to get all the matches.
join returns a string, reverse is not a string method but an array method.

you are outputting result, and nothing after is being executed. But a return is valid only inside a function, and it doesn’t look like you are in a function.

What is this comparison for? str is a string, i is a number. What do you want to obtain from their comparison?

this is uncomplete

Also, you need to get the string with only the alphanumerical characters, I am unsure how that regex would reach this.

so I Created the below function

function palindrome
(str) {
let newstr = str.replace(/[^A-Za-z0-9_.]/g, “”).join().reverse();
for (let i = 0; i < (newstr.length)/2; i++);
if (newstr [i]!== newstr[newstr.length-i-1]){
return${str} is not a palindrome ;
}
else{
return ${str} is a palindrome;
}
}

am I on the right track? also Im not getting output when check-button is clicked Im not sure if I should add a onclick event to the input or button element because I already have a onclick element that alerts the user if there is no text in the input box

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.