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
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.
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.