Tell us what’s happening:
When running the test im getting an error in some parts, for example:
A man, a plan, a canal. Panama.
When copy and pasting that string to the input box in the preview, im getting the output that it is indeed a palindrome, but test its telling me its incorrect, not sure whats happening.
Your code so far
const textInput = document.getElementById('text-input');
const checkBtn = document.getElementById('check-btn');
const results = document.getElementById('result');
let normalizedStringArray;
let isPalindrome = true;
const palindromeChecker = () => {
if (textInput.value === "") {
alert('Please input a value');
} else {
stringNormalizer();
for (let i = 0; i < normalizedStringArray.length / 2; i++) {
if (normalizedStringArray[i] !== normalizedStringArray[normalizedStringArray.length - 1 - i ]) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
results.innerHTML = `<p class="resultText"><span class="bold">${textInput.value}</span> is a palindrome.</p>`;
} else {
results.innerHTML = `<p class="resultText"><span class="bold">${textInput.value}</span> is not a palindrome.</p>`;
}
textInput.value = "";
}
};
const stringNormalizer = () => {
normalizedStringArray = textInput.value.toString().toLowerCase().replace(/[\W_]+/g, '').split('');
}
checkBtn.addEventListener('click', palindromeChecker);
textInput.addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
palindromeChecker();
}
});
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
