At first, clicking on the button element with no text added to the input element, the alert would appear. But now, the button doesn’t even respond. Have I deleted something by accident?
Have you solved it? If not, I would suggest that, if nothing at all is working then you should check if your JavaScript is connected to your HTML using a <script> tag.
Instead of defining userInput as a global variable, I’ve modified the event listener to allocate all four global variables inside it, and now the error disappears, but steps 5 and beyond are still a wash. resultText was read only, and that throws and error as well, so I’ve defined it with let instead.
document.getElementById("check-btn").addEventListener("click", () => {
const userInput = document.getElementById("text-input");
let resultText = document.getElementById("result");
const regex = /\W/g
if (userInput.value === "") {
alert("Please input a value");
}
const cleanInput = userInput.toString().toLowerCase().replace(regex, "");
const reverseInput = cleanInput.split("").reverse().join("");
if (cleanInput === reverseInput) {
resultText = `${userInput.value} + is a palindrome`;
} else {
resultText = `${userInput.value} + is not a palindrome`;
}
})
That was not the issue. You still did not say what resultText is. Try logging it and look at what is showing in your browser’s console (not the fCC console).
I got it now! The regex was wrong, and using resultText in the last conditional was missing something too. I’ve made some more changes, but mentioning them will probably get my response deleted. Thank you.