Build a Palindrome Checker Project

const checkButton = document.getElementById(“check-btn”);
const textInput = document.getElementById(“text-input”);
const result = document.getElementById(“result”);
const str = textInput.innerText.toLowerCase().replace(/^a-z0-9/g, “”);

function noInput() {
if (textInput.innerText === “”) {
alert(“Please input a value”);
result.innerText = “”;
}
}

function palindrome() {
if (str === str.split(‘’).reverse().join(‘’)) {
result.innerText = ${textInput.innerText} is a palindrome;
} else {
result.innerText = ${textInput.innerText} is not a palindrome;
}
}

checkButton.addEventListener(“click”, palindrome);
checkButton.addEventListener(“click”, noInput);

I’ve been trying for days to figure this out. The way I have it, it gives me the alert but it gives me one even if I do have a value and I can’t make my result appear when I have a value.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/build-a-palindrome-checker-project/build-a-palindrome-checker

Hi there!

The constant global variable isn’t works. Place it within the function.

And here you need to compair input value, not innerText.

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