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"
}
});
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.
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?
When the #text-input element contains an alphanumeric palindrome, the #result element should correctly identify it as a palindrome.
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.