Build a Palindrome checker

here my code below all my tests pass except test 10 and test 14 I dont understand how my code can reverse() and get results for my other tests except these to my code is below

const textInput = document.getElementById("text-input");

const checkButton = document.getElementById("check-btn");

const result = document.getElementById("result");



checkButton.addEventListener("click",() => { 
const replaced = textInput.value.replace(/[^a-z0-9]/g, "").toLowerCase()
if(textInput.value === ""){

  alert("Please input a value")
}

  else if(textInput.value === 1) {
  result.innerText = `${textInput.value} is a palindrome`
} 
else if (replaced === [...replaced].reverse().join(" ")){
result.innerText = `${textInput.value} is a palindrome`
}
else {result.innerText = `${textInput.value} is not a palindrome` }







});

Your regex should not match upper case letters A-Z.


Why did you add that condition ? I think you can remove it.


your join() method should take empty string "" as its parameter.
What you did " " will insert that blank space between each character after reversing the array.

Example:

let str = "jspandill";

let reverseJoined = [...str].reverse().join("");
console.log(reverseJoined);  // output: llidnapsj
1 Like

can you share also your html so that we can debug properly?

1 Like

but it works
image

2 Likes

Hello @jspandill!

What is certain is that you will succeed here, especially after all of your effort.

What is test number 10 asking for?

Why do you think test number 10 isn’t passing?

I have created a codepen with your code and can see straight away that there may be an issue with the quotes you are using in your variable assignments. Try changing those to single quotes.

Does this help?

1 Like

uh my bad, sorry.

I edited my reply.

1 Like

yes here`s the html

<!DOCTYPE html>

<html lang="EN" >

<head>

<meta charset="UTF-8"></meta>

<meta name="viewport" content="device-divice=width, initial-scale=1.0"></meta>

<link rel="stylesheet" href="styles.css"></link>

<title>Palindrom Checker</title>

</head>

<body>

<input id="text-input"></input>

<button id="check-btn">check</button>

<div id="result"></div>

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

</body>

</html>

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

what are you checking in this line?

here if the input is eye you end comparing eye and e y e so this will never be true, you want to join with an empty string "" not a space " "

1 Like

yes figured it out had to add “.length” to my else if condition

1 Like