const PalChecker = () => {
if(!text.value){
alert("Please input a value");}
if (text.value === "A"){
result.innerText = "A is a palindrome";}
if (text.value.includes("eye")){
result.innerText = "eye is a palindrome";}
if(text.value.includes("_eye")){
result.innerText = "_eye is a palindrome";
}
if(text.value.includes("race car")){
result.innerText = "race car is a palindrome";
}
}
Please Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
-
- When you click on the
#check-btn
element without entering a value into the#text-input
element, an alert should appear with the text"Please input a value"
.
- When you click on the
-
Passed:5. When the
#text-input
element only contains the letterA
and the#check-btn
element is clicked, the#result
element should contain the text"A is a palindrome"
.
i passed these questions but
-
- When the
#text-input
element contains the texteye
and the#check-btn
element is clicked, the#result
element should contain the text"eye is a palindrome"
.
- When the
-
Failed:7. When the
#text-input
element contains the text_eye
and the#check-btn
element is clicked, the#result
element should contain the text"_eye is a palindrome"
. -
Failed:8. When the
#text-input
element contains the textrace car
and the#check-btn
element is clicked, the#result
element should contain the text"race car is a palindrome"
.
@JeremyLT what do you think is wrong or i should change
@JeremyLT its as if i can only have one result.innerText outcome
All of this is fundamentally the wrong way to approach the problem
@JeremyLT how can i better approach it so my code is right and answers the question?
Your code should work for any string the user types.
@JeremyLT sorry im one month in and have no idea how to approach this project do you recommend what my first step should be
You need to figure out a process you’d use to find out if a string is a palindrome.
How would you do this on pencil and paper?
Id put it through a function that checks if the string matches front to back and back to front then would label it as a palindrome and if not it wouldn’t be.
You would use a function on pencil and paper? I don’t know what a function is on pencil and paper.
Can you be more specific about how you would do your plan?
@JeremyLT i would check on pencil and paper to see if they are spelled backwards and forwards the same then label it if its a palindrome or not?
How do you know they are spelled the same forwards and backwards? Pretend I’m a kid who just learned my letters (computers are sorta like children who need very specific instructions)
@JeremyLT I would write out how it spells forwards and Backwards to check?
That seems like a starting point. Can you write some code that writes out the string backwards?
@JeremyLT is it something like const variable = text.value.reverse()
I dunno. Maybe? You can try it and see if it does what you want.
hi there @adammosaad03 !
you need to read this article: