Build a Palindrome Checker Project - Build a Palindrome Checker

I can see that my code updates the innerHTML of the #results div but all of the tests are failing.

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Palidrome Checker</title>
    <link rel="stylesheet" href="styles.css" />
</head>
<body>
  <main>
  <div id="checkbox">
    <h4>Enter in text to check for a palindrome:</h4>
    <input type ="text" id="text-input">
    <button type="button" id="check-btn">Check</button>
    <div id="result"></div>
  </div>
  <div id="explanaition">
  <p> A <i>palindrome</i> is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
  </div> 
  <script src="script.js"></script>
  </main>
</body>
</html>
/* file: styles.css */
body {
  background-color: #135589;
  font-family: Arial, Helvetica, sans-serif;
  color: white; 
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  
}
#explanaition {
  border: solid white 3px;
  background-color: #ff8200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 20px;
  margin: 10px 0;
}
#checkbox {
  margin: 0 15% 0 15%;
  padding: 10px;
  border: solid white 3px;
}


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


function cleanUp (str) {
const regex = /[\W_+]/g;
return str.replace(regex, '');
}



const palindrome = () => {
  if(textInput.value === ""){
    alert("Please input a value")
  }
  const input = textInput.value;
  const string = cleanUp(input);
  const lowerString = string.toLowerCase();
  for (let i = 0; i < lowerString.length/2; i++) {
    for (let j = lowerString.length - 1; j >= i; j--){
    let letterI = lowerString[i];
    let letterJ = lowerString[j];
    if (letterI !== letterJ) {
    result.innerHTML = `${input} is not a polindrome`;
    return;
    }
    i++;
    result.innerHTML = `${input} is a polindrome`;
    }
  }
  
};

checkBtn.addEventListener("click", 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

try writing palindrome instead

OMG! I just spent like 1hrs trying to figure this out :sweat_smile:
Thanks!

1 Like

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