Palindrome checker

Stop right there. Do not look for other’s solutions to this project. This should be your own work. You will learn much more if you do this on your own.

It feels like you don’t quite understand what your code is doing and you are trying to google for quick answers instead of figuring it out. Before you can code a solution, you have to know what you want the code to do. Please explain in English, not code, what the following code is supposed to do.

checkBtn.onclick = () => {
 if (value) {
   const cleanValue = value.replace(/[^A-Za-z0-9]/g).toLowerCase()
   const reversedValue = cleanValue.split('').reverse().join('').toLowerCase()
   if(cleanValue === reversedValue){
     result.innerText = `${value} is a palindrome`
     console.log(cleanValue)
     console.log(reversedValue)
   } else{
     result.innerHTML = `${value} is not a palindrome`;
     console.log(cleanValue)
     console.log(reversedValue)
   }
 } else {
   alert("Please input a value")
 }
}

Okay got it.

I want my code to display the text “A is a palindrome” in my palindrome checker.

Can you help me get this done.

I have been able to make an alert appear indicating “Please input a value”

This is probably going to be the last time I ask unless you answer the question I am asking. It’s nothing personal. I’ve spent quite a bit of time with you on this and maybe I am not the best person to help you?

In my last post, I asked you to explain what your code is doing. I am not convinced that you understand your own code. Until you do that, you won’t be able to solve this project. So please, explain in words what your code is doing.

My code is trying to check if a word or sentence is a Palindrome

If this doesn’t work for you, thanks for your help.

But how do you think your code works? What steps do you think it is taking?

Was this explained in the previous lessons?

In the previous course there was nothing regarding palindrome checker.

So, I don’t know how I am expected to know this

You are not supposed to copy code from anywhere on this.

You need to write your own code representing how you would solve this problem yourself.

It seems like you may have copied this code. Note that copying code for the certification projects is against the academic honestly agreement and invalidates your certification.

The JS team is working on updates to the curriculum so you will feel more confident to solve challenges on your own

but for now, I would suggest looking at the first 6 challenges from the legacy JS algorithm scripting section

2 Likes

Sorry, I hit enter before I was finished typing.

But the reason why I am suggesting to go through those is because they are small problem solving exercises that will help you fill in the gaps on how to break a problem down into pieces and solve it

which is the required skill you need to solve this palindrome checker project as well as the other projects

1 Like

Okay noted.

I did not copy the code.

I wrote the html and the CSS.

I was having issues with js.

I tried to check online if I could find similar solution, when it seems responses might be slow on the forum.

If this is wrong I am sorry.

Ok, can you say what you wrote that JS to do? What steps that code is supposed to be taking?

First, I tried to declare the variable using their id

The instruction was given to make sure certain elements and variables ( input, button and result) had a specific id

Ok, but can you talk about how you think your JavaScript code should work?

I think it should work with the button element similar to what I learnt in the Building of the role playing game : using the query selector and the onclick

Thank you for this I will work on it.

1 Like

I’m definitely confused here.

You definitely should be looking at zero palindrome project solutions online while doing this project.

Got it, will stick to what I know