Tell us what’s happening:
All the “is a palindrome” tests run but the “is not a palindrome” fail. Please tell me what I’m doing wrong
Your code so far
<!-- file: index.html -->
<!DOCTYPE>
<html>
<head></head>
<body>
<div class='container'>
<p>Enter in text to check for a palindrome:</p>
<input id="text-input" required/>
<button id="check-btn">Check</button>
<div id="result">
</div>
</div>
<script src='./script.js'></script>
</body>
</html>
/* file: styles.css */
/* file: script.js */
const textInput = document.getElementById('text-input');
const checkButton = document.getElementById('check-btn');
const checkResult = document.getElementById('result');
function isPalindrome(text) {
if(text === ''){
return false
}
const regex = /[W_]/g;
const userInput = text.toLowerCase().replace(regex, '')
const word = userInput.split('').reverse().join('');
if(word === userInput){
return true;
}
}
checkButton.addEventListener('click', (e) => {
e.preventDefault();
if(textInput.value === ""){
alert('Please input a value');
} else if(isPalindrome){
checkResult.innerHTML = `<p>${textInput.value} is a palindrome </p>`
} else{
checkResult.innerHTML = `<p>${textInput.value} is not a palindrome </p>`
}
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker