Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

Number 15 on the Palindrome Checker project wants “1 eye for of 1 eye.” to say that it’s not a palindrome… but it is a palindrome? why would the test ask for it to say it’s not a palindrome. All of the other test were cleared.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
  <title>Palindrome Checker</title>
</head>
<body>
  <div>
    <h1>Is it a Palindrome?</h1>
    <p>Enter in a text to see if it's a palindrome.</p>
    <input id="text-input"></input>
    <button id="check-btn">Check</button>
    <span id="result"></span>
  
  </div>
  <script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const textInput = document.getElementById('text-input');
const checkBtn = document.getElementById('check-btn');
const result = document.getElementById('result');


function clean(str){
  const regex = /[0-9\+-\s\_\,\/\.\(\)\:]/g;
  let a = str.replace(regex, '');
  let b = a.toLowerCase();
  return b;
}

function check(str){
  for (let i=0 ; i < str.length; i++){
    if(str[i]!==str[str.length - i - 1]){
      return false;
    }
  }
  return true;
}


function getResult(){
  let firstClean = clean(textInput.value);
  let output = check(firstClean);
  if(textInput.value === ""){
     return alert("Please input a value");
  }
  else if (output === false){
    return result.innerHTML= `${textInput.value} is not a palindrome.`;
  }
  else if (output === true){
    return result.innerHTML= `${textInput.value} is a palindrome.`;
  }
   
}

checkBtn.addEventListener ('click', getResult);

/* file: styles.css */

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

Nope. You can test by removing spaces in the original string then console.log to see if the new string equals the new string reversed.

if I remove the spaces, it would be “1eyeforof1eye.”
if I remove the numbers and period it would be “eyeforofeye”
“eyeforofeye” is the same forwards and backwards. Just like “racecar” the e overlaps, in “eyeforofeye” the r overlaps. It’s still a Palindrome.

Where does it say you should remove the numbers?

2 Likes

Ahh! I didn’t question it for the other tests since those numbers were apart of the palindrome respectively. Thank you!

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