Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

i cant seem to get any fictionality working, please help

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 href="./styles.css" rel="stylesheet">
    <title>Palindrome Checker</title>
  </head>
  <body>
    <h1>Is it a Palindrome?</h1>
    <div class="container">
    <div class="con1">
      <label for="text-input">Enter in text to check for a palindrome:</label>
      <input id="text-input" type="text" />
      <button id="check-btn">check</button>
      <div id="result"></div>
    </div>
    <div class="con2">
      <p>💡 A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
    </div>
    </div>
  </body>
</html>
/* file: script.js */
const userInput = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const result = document.getElementById("result");

const palindromeCheck = (str) => {
  const regex = /[\W_]/g ;
  const firstStr = str.toLowerCase().replace(regex,'');
  const reverseStr = firstStr.split('').reverse().join('');
  if(str===''){
     alert("Please input a value");
  }
  else if(firstStr === reverseStr) {
    result.innerText = `${str} is a palindrome`;
  }
  else {
    result.innerText = `${str} is not a palindrome`;
  }
}

checkButton.addEventListener('click',palindromeCheck(userInput.value));
/* file: styles.css */
body {
  background-color: #1b1b32;
  color: #f5f6f7;
  font-family: Tahoma;
  width: 100%;
  height: 100vh;
  margin: 0;
  font-size: 16px;

}

.container {
  width: 100%;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 10px;
}

h1 {
   text-align: center;
  text-transform: uppercase;
  padding: 32px;
  background-color: #0a0a23;
  color: #fff;
  border-bottom: 4px solid #6200ee
}

input {
  width: 300px;
  min-height: 2em;
  margin: 10px;
  border: none;
  border-bottom: 2px solid #5a01a7;
  background-color: #f5f6f7;
  text-align: center;

}

.con1 {
  max-width: min(100vw, 450px);
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 20px;
  margin: 10px 0;
  background-color: #f5f6f7;
  color:black;
  border-radius: 18px;
  box-shadow: 1px 10px 10px #6200ee

}

.con2 {
  width: min(100vw, 450px);
  font-size: 1.3rem;
  min-height: 140px;
  background-color: #00471b;
  margin-top: 20px;
  padding: 20px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

label {
  color: #0a0a23;
  margin-bottom: 20px;
}

button {
  width: 90px;
  border: none;
  padding: 10px;
  border-radius: 15px;
  background-color: #5a01a7;
  color: #fff;
  cursor: pointer;
}

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

have you checked if your JavaScript is working at all? did you remember to connect the two files together?

1 Like

Your event listener is not set up correctly.