const textInput = document.getElementById('text-input');
const checkButton = document.getElementById('check-btn');
const resultAnswer = document.getElementById('result');
let isPalin = true;
const regex =/[^A-Za-z0-9]/g;
function handlePalindrome(e) {
e.preventDefault();
resultAnswer.innerHTML = '';
if (textInput.value === "") {
alert("Please input a value");
return;
}
const rawInputStr = textInput.value;
const cleanInputStr = rawInputStr.replaceAll(regex, '').toLowerCase();
const textArray = cleanInputStr.split('');
console.log(textArray);
console.log(cleanInputStr);
if (textArray.length % 2 === 0) {
console.log('yes')
for (let i=0; i <= textArray.length/2-1; i++) {
if (textArray[i] !== textArray[textArray.length-1-i])
{
isPalin = false;
break;
}}} else {
for (let i=0; i<(textArray.length-1)/2; i++) {
if (textArray[i] !== textArray[textArray.length-1-i])
{
isPalin = false;
break;}
}
}
console.log(isPalin);
resultAnswer.innerText = `${rawInputStr} ${isPalin ? "is" : "is not"} a palindrome`
}
checkButton.addEventListener("click", handlePalindrome)
In the Palindrome Project, my code correctly identifies when the input is or is not a palindrome, however when I run the tests errors occur on only some of the requirements (10, 11, 14, 16, 18) even though when my code works for those scenarios. Is there a bug in my code causing the website to not check those boxes?