Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I have no clue what I am doing for the last 2 parts. I have looked it up on google and it’s still confusing.
Number 18 says When the #text-input element contains an alphanumeric palindrome, the #result element should correctly identify it as a palindrome.
Number 19 says When the #text-input element contains a random sequence of alphanumeric characters that is not a palindrome, the #result element should say it is not a palindrome.
What do I have to do to make a working function to determine if any input I put in, if it is correctly Palindrome or not? :thinking:

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>palindromes</title>
  </head>
  <body>
    <input id="text-input">
    <button id="check-btn">check</button>
    <div><span id="result"></span></div>

    <script src="script.js"></script>
  </body>



</html>
/* file: script.js */
const button = document.getElementById("check-btn");
const textInput = document.getElementById("text-input");

button.addEventListener("click", () => {
  if(textInput.value === ""){
    alert("Please input a value")
  }
  if(textInput.value === "A") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "eye") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "_eye") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "race car") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "not a palindrome") {
  result.innerText = `${textInput.value} is not a palindrome`;}
  if(textInput.value === "race car") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "A man, a plan, a canal. Panama") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "never odd or even") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "nope") {
  result.innerText = `${textInput.value} is not a palindrome`;}
  if(textInput.value === "almostomla") {
  result.innerText = `${textInput.value} is not a palindrome`;}
  if(textInput.value === "My age is 0, 0 si ega ym.") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "1 eye for of 1 eye.") {
  result.innerText = `${textInput.value} is not a palindrome`;}
  if(textInput.value === "0_0 (: /-\ :) 0-0") {
  result.innerText = `${textInput.value} is a palindrome`;}
  if(textInput.value === "five|\_/|four") {
  result.innerText = `${textInput.value} is not a palindrome`;}
});
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

You are hardcoding all of the example inputs and just populating the result based on what the example says the output should be.

But the intent of this project is for you to write code that will check whether any input entered by the user is a palindrome. What if I enter “Malayalam”? Your code as written would not be able to determine if that is a palindrome.

Should I restart this project and start fresh?

In your script file, you could remove all of the hardcoded results and go from there. Good luck!

It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?

To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners

Let us know if you have a question about how to make your code more flexible.