Build a Palindrome Checker Project - Build a Palindrome Checker

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

Welcome to the forum @fetKet

Try using equality operator instead of strict.

Just tried it.
The alert appears, but does not pass the test.

Happy coding

Alert appears but has to be clicked twice. Still can not get the tick for the " When you click on the #check-btn element without entering a value into the #text-input element, an alert should appear with the text Please input a value ." condition

Do all of your other tests pass?

yeah. all except this condition.

Since the lessons leading up to this challenge do not use the html function call method of clicking a button, I would remove that from your code and only use the is event listener method. Also, it isn’t clear why you use an event listener in a function that is called due to said event.

I did re-write the code and it did work. Thank you.