Build a Palindrome Checker

Hi,

Tests 5 to 17 are not passing. When I try the tests manually they return as the answer wanted. I checked my filtered and reversed variables and they are matching. What have I done wrong here.

Thanks.

Link to test Build a Palindrome Checker

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Palindrome Checker</title>
  </head>
  <body>
    <div class="container">
      <label for="text-input" class="label">Enter your word</label><br />
      <input type="text" id="text-input" class="element" /><br />
      <button id="check-btn" class="element">Submit</button>
      <p id="result"></p>
    </div>
  </body>
  <script>
    var text = document.getElementById("text-input");
    var checkBtn = document.getElementById("check-btn");
    var result = document.getElementById("result");
    var regexRule = /[^a-z0-9]/gi;
    checkBtn.addEventListener("click", () => {
      if (text.value === "") {
        alert("Please input a value");
      } else {
        var filtered = text.value.replace(regexRule, "").toLowerCase();
        var reversed = filtered.split("").reverse().join("");
        console.log(filtered);
        console.log(reversed);
        if (filtered === reversed) {
          result.innerHTML = text.value + " is a palindrom";
        } else {
          result.innerHTML = text.value + " is not a palindrom";
        }
      }
    });
  </script>
</html>

I think your code will pass all tests if you correct your spelling of ‘palindrome’ in both of the return messages:

As a side point, you’d be better using let or const to declare variables, as var is all but deprecated now.

1 Like

You are the best and thanks for the recommendation I’ll do that now on.

1 Like