Build a Palindrome Checker Project - Build a Palindrome Checker

Please help me with this code, it doesn’t want to run

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
   <title>Palindrome Checker</title>
   <style>
      body {
         text-align: center;
         font-family: Arial, sans-serif;
      }
      h1 {
         margin-top: 20px;
      }
      #text-input {
         margin-top: 20px;
         padding: 5px;
         font-size: 16px;
      }
      #check-btn {
         margin-top: 10px;
         padding: 10px 20px;
         background-color: #4CAF50; /* Green */
         color: white;
         font-size: 16px;
         border: none;
      }
      #result {
         margin-top: 20px;
         font-size: 18px;
      }
   </style>
</head>
<body>
   <h1>Palindrome Checker</h1>
   <input type="text" id="text-input" placeholder="Enter a word or phrase">
   <button id="check-btn">Check</button>
   <div id="result"></div>

   <script>
      function isPalindrome(word) {
         var reverseWord = word.split('').reverse().join('');
         return word.toLowerCase() === reverseWord.toLowerCase();
      }

      document.getElementById('check-btn').addEventListener('click', function() {
         var input = document.getElementById('text-input').value.trim();

         if (input === '') {
            alert('Please input a value');
         } else if (isPalindrome(input)) {
            document.getElementById('result').textContent = input + ' is a palindrome';
         } else {
            document.getElementById('result').textContent = input + ' is not a palindrome';
         }
      });
   </script>
</body>
</html>
/* file: styles.css */

/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

what issues are you having? what does it mean that it doesn’t want to run?

Here, you are just taking the input and trimmed it.
But a palindrome word as you see here at the bottom of the example project: Palindrome Project FCC

A palindrome is a word or sentence that’s spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

So you need to find a way to replace any of those spaces and punctuation with an empty string "" so you can check correctly for a palindrome.

Good Practice: use let keyword instead of old var.

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