checkBtn.addEventListener(“click”, () => {
let isPalindrome = true;
let alphaNumericString = new String(textInput.value).trim().toLowerCase().replace(/[^a-zA-Z0-9]/g,“”);
if (alphaNumericString.length == 0) {
alert(“Please input a value”);
} else {
for (i = 0; i < alphaNumericString.length / 2; i++) {
if(alphaNumericString[i] != alphaNumericString[alphaNumericString.length - i - 1]) {
isPalindrome = false;
break;
}
}
result.innerText = isPalindrome ? textInput.value + " is a palindrome" : textInput.value + " is not a palindrome";
}
});
Palindrome Test
Enter
body {
background-color: black;
color: white;
}
This is very simple as you see but the ‘Run the Tests’ buttonn fails to test this code.