# Palindrome Checker Help

**URL:** <https://forum.freecodecamp.org/t/palindrome-checker-help/687720>\
**Category:** I Built This\
**Created:** [April 29, 2024, 3:44pm UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720 "2024-04-29T15:44:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirajhaq](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mirajhaq](https://forum.freecodecamp.org/u/mirajhaq)\
**Post date:** [April 29, 2024, 3:44pm UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/1 "2024-04-29T15:44:41Z")

</div>

Hi, I am trying to complete the Palindrome Checker Project.  
I wrote my code on VS code, all looks perfect to me. I did all the tests manually and they all work, but freecodecamp still thinks my tests are running wrong.  
Any feedback is really appreciated thank you

```auto
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="styles.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Palindrone Checker</title>
  </head>

  <body>
    <h1>Palindrome Checker</h1>
  
    <input type = "text" id = "text-input">
    <button id ="check-btn" onclick = "press()">Press me</button>
    <div id ="result">Results Div</div>

    <script src="script.js"></script>
  
  </body>
</html>
type or paste code here

```

javascript:

```auto
const textInput = document.querySelector("input");
let filterInput = textInput.value;
let textLength = filterInput.length;

let resultEl = document.getElementById("result")

textInput.addEventListener("keyup", () => {
    filterInput = textInput.value.replace(/[^A-Z0-9,.]/ig, "");
    textLength = filterInput.length
    filterInput = filterInput.toLowerCase();
});

function press() {

    if (textLength === 0) {
        alert ("Please input a value")
    } else {
        check()

    }
}

function reverseString(filterInput) {
    var splitString = filterInput.split("");
    var reverseArray = splitString.reverse();
    var joinArray = reverseArray.join("");

    return joinArray
}

function check() {
    let reverseEl = (reverseString(filterInput))
    console.log(filterInput)
    console.log(reverseEl)

    if (filterInput === reverseEl) {
        console.log("Palindrome")
        resultEl.textContent = (textInput.value + " is a palindrome");
    } else {
        console.log("Not a Palindrome")
        resultEl.textContent = (textInput.value + " is not a palidrome");
    }

}

```

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [April 29, 2024, 3:53pm UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/2 "2024-04-29T15:53:20Z")

</div>

> [@mirajhaq](#):
>
> ```auto
> textInput.addEventListener("keyup", () => {
> filterInput = textInput.value.replace(/[^A-Z0-9,.]/ig, "");
> textLength = filterInput.length
> filterInput = filterInput.toLowerCase();
> });
> 
> ```

The first problem is that this is not being triggered by the tests. I would put this logic with your `press` function

---

<div class="post-metadata">

**Author:** ![mirajhaq](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mirajhaq](https://forum.freecodecamp.org/u/mirajhaq)\
**Post date:** [April 30, 2024, 10:17am UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/3 "2024-04-30T10:17:08Z")

</div>

Thank you so much for your reply, so I tried putting everything into the “press” function.  
All tests are working now, except for when its not a palindrome. It still says its not passing.  
Really not sure why 😕

edit: I think its because of the else if, and then the final else condition, if I make a “check function” that does the whole check it wont pass the tests if its a palindrome or not

```auto
let resultEl = document.getElementById("result")

function press() {
    let textInput = document.querySelector("input");
    let filterInput = textInput.value.replace(/[\\,_.0-9]/ig, "");
    filterInput = filterInput.toLowerCase()
    let textLength = filterInput.length;
    console.log(textLength)

    let reverseEl = (reverseString(filterInput))
    console.log(filterInput)
    console.log(reverseEl)
    if (textLength === 0) {
        alert ("Please input a value")
    } else if (filterInput === reverseEl) {
        resultEl.textContent = (textInput.value + " is a palindrome");
        console.log("Palindrome")
    } else {
        resultEl.textContent = (textInput.value + " is not a palidrome");
        console.log("Not a palindrome")
    }
}

function reverseString(filterInput) {
    var splitString = filterInput.split("");
    var reverseArray = splitString.reverse();
    var joinArray = reverseArray.join("");

    return joinArray
}

```

---

<div class="post-metadata">

**Author:** ![MostafaElbadry](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@MostafaElbadry](https://forum.freecodecamp.org/u/MostafaElbadry)\
**Post date:** [April 30, 2024, 11:07am UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/4 "2024-04-30T11:07:42Z")

</div>

> [@mirajhaq](#):
>
> ```JS
> (textInput.value + " is not a palidrome")
> 
> ```

You have a typo here.

* * *

> [@mirajhaq](#):
>
> ```auto
> textInput.value.replace(/[\\,_.0-9]/ig, "")
> 
> ```

This will remove numbers. but, if you re-read the note at the challenge again:

> You’ll need to remove **all non-alphanumeric characters** (punctuation, spaces and symbols)

It says **non-alphanumeric** so you need to keep numbers also.

* * *

Your code should now pass all tests except for one…  
`0_0 (: /-\ :) 0-0`

back to your regex `/[\\,_.0-9]/ig`  
(after you edit it to keep numbers)

you will see that you are not removing `:` , `-`, `/` and parentheses `()`. so you can add them manually like what you did, or think of a better way to do it.

_Think about character classes like `\d` for example_

---

<div class="post-metadata">

**Author:** ![mirajhaq](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mirajhaq](https://forum.freecodecamp.org/u/mirajhaq)\
**Post date:** [April 30, 2024, 11:50am UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/5 "2024-04-30T11:50:10Z")

</div>

Thank you so much, I need to look closer!

I’ve fixed the typo and fixed the regex to include numbers and to remove the `:` , `-` , `/`  
Code is finally passing all tests 🤩 🤩

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [October 29, 2024, 11:50pm UTC](https://forum.freecodecamp.org/t/palindrome-checker-help/687720/6 "2024-10-29T23:50:55Z")

</div>

Closed on October 29, 2024, 11:50pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
