Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

When I run the tests only the first 3 user stories pass, and the rest fail. But I tried it in codepen and I believe I am getting the right responses.

Your code so far

<!-- file: index.html -->
<h1>Palindrome Checker</h1>
<h3>Check whether a word is a palindrome</h3>
<p>A word is a palindrome if it can be spelled forward and backward, ignoring punctuation, case, and spacing.</p>
<div>Enter your word here:</div>
<input type="text" id="text-input"><br><br>
<button id="check-btn" type="button" onclick="palindromeChecker()">Check</button>
<div id="result"></div>
/* file: styles.css */

/* file: script.js */
function palindromeChecker() {
    const textInput = document.getElementById("text-input").value;
    console.log("button clicked");

    const result = document.getElementById("result");

    if (textInput.length === 0) {
      alert("Please input a value");
      return;
    }

    const cleanedInput = textInput.toLowerCase().replace(/[\W_]/g, "");
    const reversedInput = cleanedInput.split('').reverse().join('');

    if (cleanedInput === reversedInput) {
      result.textContent = `${textInput} is a palindrome!`;
    } else {
      result.textContent = `${textInput} is not a palindrome.`;
    }
  }

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

Is it your punctuation in your result text?

I found the solution and its driving me up the wall. I needed a script tag in the html and it works fine now. ex. <script src="script.js>

1 Like

You just saved me from 2 days of frustration. I had a typo in my script tag.