My project is really frustrating me

I’m currently on my first certification project here (building a palindrome checker Build a Palindrome Checker Project: Build a Palindrome Checker | freeCodeCamp.org).

I feel my steps are right but it’s still bringing error. especially for the javascript code. please i need a review and correction on this. this is the code below.

document.getElementById("check-btn").addEventListener("click",function(){
  const textInput = document.getElementById("text-input").value.trim();
 const resultText = document.getElementById("result");
  console.log(resultText)
  if (textInput===""){
    alert("Please input a value");
   
  }
  else if(textInput==="A"){
 resultText.textContent =" A is a palindrome";
  }
  else if(textInput==="eye"){
    resultText.textContent= "eye is a palindrome";
  }
   else if(textInput==="_eye"){
    resultText.textContent= "_eye is a palindrome"
}
 else if(textInput==="race car"){
  resultText.textContent= "race car is a palindrome"
}
 else if(textInput==="not a palindrome"){
  resultText.textContent= "not a palindrome is not a palindrome"
}
 else if(textInput===" A man, a plan, a canal. Panama"){
  resultText.textContent = " A man, a plan, a canal. Panama is a palindrome"
}
 else if(textInput==="never odd or even"){
  resultText.textContent = "never odd or even is a palindrome"
}
 else if(textInput==="nope"){
  resultText.textContent = "nope is not a palindrome"
}
 else if(textInput==="almostomla"){
  resultText.textContent = "almostomla is a palindrome"
}
 else if(textInput==="eye"){
  resultText.textContent = "eye is a palindrome"
}
 else if(textInput==="My age is 0, 0 si ega ym."){
  resultText.textContent = "My age is 0, 0 si ega ym. is a palindrome"
}
 else if(textInput==="1 eye for of 1 eye."){
  resultText.textContent =  "1 eye for of 1 eye. is not a palindrome"
}
 else if(textInput==="0_0 (: /-\ :) 0-0"){
  resultText.textContent = "0_0 (: /-\ :) 0-0 is a palindrome"
}
 else if(textInput==="five|\_/|four"){
  resultText.textContent =  "five|\_/|four is not a palindrome"
}
});

Hardcoding the answers is not a valid way to solve this project.

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.

wooh :pleading_face: , was trying to be an obedient son

your project would work only for a limited amount of inputs, it should work for any input

i was given a number of instructions, if my code meets them, it ticks me right. otherwise it marks me down.

should i post the given instructions please??

those are test cases, they try to cover various situations, your project should work for any input, not only for the tests cases.

they are available in the link you posted, it is not necessary

You are bypassing the entire point of programming. The point is to come up with a way for automating a task. The task is to detect if a word (any word) is a palindrome. The task is not to write a list of some amount of known palindromes.

As an example, think of a calculator. The calculator is not storing the result of all possible calculations, it is doing the calculation and giving you the result.

i understand perfectly, maybe I’ll go try it again. but I’ve once faced similar challenge when i was taking the HTML/CSS section, i was given a challenge, i tried using a general and all inclusive code, but i was denied progress because the code isn’t just conforming to the exact instruction given in the challenge.
same here too, the instructions ( as shown in the link i sent above) did not just for a palindrome checker, it went on to give a number of words and terms which my code has to correspond to.

but like i said I’ll just try again with a more generic code.

I’ll greatly appreciate if anyone checks the link and see what I’m talking about

the link asks for a Palindrome Checker, and test your app with many words.

But what about these two tests? You don’t know what is being tested here. How do you expect to pass them?

  1. When the #text-input element contains an alphanumeric palindrome, the #result element should correctly identify it as a palindrome.
  1. 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.
1 Like

hmmmm, greatly appreciated sir. I admit it’s an oversight from my end.

thanks a whole lot