Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

Why my code is not passing?

Your code so far

<!-- file: index.html -->
<html lang="en">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Palindrome Checker App</title>
    <link rel="stylesheet" src="styles.css"/>
    <input id="text-input" type="text" value=""/>
    <button id="check-btn">Check</button>
    <div id="result"></div>
    <script src="script.js"></script>
/* file: styles.css */

/* file: script.js */
const checkButton = document.getElementById("check-btn");
const textInput = document.getElementById("text-input");
const resultElement = document.getElementById("result");
let textValue = "";

textInput.addEventListener("change", (event) => {
  textValue =;

checkButton.addEventListener("click", () => {
    if(textValue === ""){
      alert("Please input a value");
    else if(textValue === "A") {
      resultElement.innerText = "A is a palindrome";
    else if(textValue === "eye"){
      resultElement.innerText = "eye is a palindrome";
    else {
      resultElement.innerText = "Please enter a valid input";

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hey, welcome to the forum.

You are not passing a lot of the tests. It would probably help if you asked a question or told us where you are stuck so we know how to help you.

else if(textValue === "eye"){
      resultElement.innerText = "eye is a palindrome";

I can tell you that this approach is not going to work. You would have to write an else if statement for every possible string that could be passed into your function, which would make your code very very long :slightly_smiling_face:

Don’t write your function to only handle the strings used in the tests. Pretend you don’t know what strings are going to be tested.

Hey paramvir2120,

I don’t want to spoil a great opportunity for you to learn, but I will still try to point you in the right direction without giving too much away :slight_smile:

A palindrome is a word, number, phrase, or other sequence of symbols that reads the same backwards as forwards.

This means that you should probably consider comparing your input to a reversed version of itself. I recommend looking up how to reverse a string.

I would also consider how your algorithm will handle special characters. For instance, look at test case 10:

A man, a plan, a canal. Panama

If you haven’t already, I highly recommend learning about regular expressions.
You can also use a resource called regex101 to help you learn how to build them.

Anyways, I hope this helps!

Thanks Anthony. Your suggestion is worth more than gold for me.

1 Like