Tell us what’s happening:
I can not seem to get alert requirement correctly.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head><script src="./script.js"></script>
</head>
<input type="text" id="text-input">
<button type="button" id="check-btn" onclick="clickMe()">Check</button>
<div id="result"></div>
</html>
/* file: styles.css */
/* file: script.js */
function isPalindrome(str) {
const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
return cleanStr === cleanStr.split('').reverse().join('');
}
function clickMe() {
document.querySelector("#check-btn").onclick = () => {
const input = document.getElementById("text-input").value;
if(input === "") {
alert("Please input a value");
}
const isPal = isPalindrome(input);
document.getElementById("result").innerHTML = `${input} is ${isPal ? "" : "not "}a palindrome`;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker