Tell us what’s happening:
This is what I have for my code so far and none of the tests except the 3 that are just do you have the right HTML elements. I know that something has to be wrong with my code but I’m not really sure what, maybe the replacing, splitting, or reversing part is whats messing up my code?
Your code so far
/* file: script.js */
const input = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const resultDiv = document.getElementById("result");
function error(){
alert("Please input a value");
}
function checkPalindrome(){
if (input.value = ""){
error()
} else {
inputList = input.replace(/^[a-z]/g, "");
inputList = inputList.split("");
inputReversed = inputList.reverse();
if (inputReverse === inputList) {
resultDiv.innerHTML = `${input} is a palindrome`
} else {
resultDiv.innerHTML = `${input} is not a palindrome`
}
}
}
checkButton.addEventListener("click", checkPalindrome);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker