Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

All the “is a palindrome” tests run but the “is not a palindrome” fail. Please tell me what I’m doing wrong

Your code so far

<!-- file: index.html -->
  <div class='container'>
    <p>Enter in text to check for a palindrome:</p>
  <input id="text-input" required/>
  <button id="check-btn">Check</button>
  <div id="result">
  <script src='./script.js'></script>
/* file: styles.css */

/* file: script.js */
const textInput = document.getElementById('text-input');
const checkButton = document.getElementById('check-btn');
const checkResult = document.getElementById('result');

function isPalindrome(text) {
  if(text === ''){
    return false

  const regex = /[W_]/g;
  const userInput = text.toLowerCase().replace(regex, '')

  const word = userInput.split('').reverse().join('');
  if(word === userInput){
    return true;

checkButton.addEventListener('click', (e) => {
if(textInput.value === ""){
  alert('Please input a value');
} else if(isPalindrome){
  checkResult.innerHTML = `<p>${textInput.value} is a palindrome </p>`
} else{
  checkResult.innerHTML = `<p>${textInput.value} is not a palindrome </p>`

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

what have you tried for debugging?

Welcome to the forum @clairy

Your function takes a parameter, however the …

else if statement is checking for truthiness.

Happy coding

1 Like

Your .js is not updating the

element for the result string. And also your function 'isPalindrome(text) takes parameter of ‘text’ and your ‘checkButton.addEventListner’ does not pass even call 'isPalindrom() function at all because you are checking 'else if(isPalindrom) <— where is the parameter for 'isPalindrom() function ‘you declared?’ Here is what you declared… “function isPalindrome(text)”.

1 Like

I corrected that and it worked! Thank you