Build a Palindrome Checker Project

So, I’m currently attempting to get done this Palindrome project, and I have all but three of the tests passed: #5, #10, and #14. I can’t figure out how to get these tests, especially #5, to pass.
Can you show me where I went wrong?

let input = document.getElementById("text-input");
let submit = document.getElementById("check-btn");
let result = document.getElementById("result")
function palindromeChecker() {
  
  let palindrome = input.value;
  if (!palindrome) {
    alert("Please input a value");
    return;
  }
  
  console.log(palindrome);
  let regex = /[\s\W_]/g;
  let formattedPalindrome = palindrome.replace(regex, '')
  console.log(formattedPalindrome)
  let formattedReversePalindrome = formattedPalindrome.toLowerCase().split('').reverse().join('');
  if (formattedPalindrome === formattedReversePalindrome) {
    result.innerHTML = palindrome + " is a palindrome"
  } else {
    result.innerHTML = palindrome + " is not a palindrome";
  }
}
submit.addEventListener("click", palindromeChecker)

Here’s the link for the project if you want to see the tests in question: Build a Palindrome Checker Project: Build a Palindrome Checker | freeCodeCamp.org

You are very close to having working code.
Try logging your formattedReversePalindrome to the console and compare it with the other variables you’ve logged.
Hopefully then you’ll see exactly why there’s an issue with the failing tests.

Aha! Thanks, @igorgetmeabrain! I think I see the problem now. It seems as if it’s checking variables with two different values. I should’ve known that even a small difference in value can mean the difference between true or false. :man_facepalming:

Now the only question is, will this actually work?
two minutes later…
Thanks so much, @igorgetmeabrain! It finally works! I just had to modify a small line of code!

1 Like