Tell us what’s happening:
I have written JS of alert method but it is not showing alert. where is the code error I could not find the error. can you help me, please?
Your code so far
<!-- file: index.html -->
<div>
<input id="text-input" placeholder="Enter text here">
<button id="check-btn">Check</button>
<div id="result"></div>
</div>
/* file: script.js */
const button = document.querySelector("#check-btn");
const result = document.querySelector("#result");
button.addEventListener("click", () => {
const input = document.querySelector("#text-input").value;
if (input==="") {
alert("Please input a value");
return;
}
const originalInput = input;
const cleanedInput = input.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const isPalindrome = cleanedInput === cleanedInput.split("").reverse().join("");
if (isPalindrome) {
result.textContent = `${originalInput} is a palindrome`;
} else {
result.textContent = `${originalInput} 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/130.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker