Tell us what’s happening:
I can not get my else statement to work. I have typed this over so many times and I just don’t see the problem. It is step number 9. I want it to say not a palindrome
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang= "en">
<head>
<meta charset= "UTF-8">
<meta name= "viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<input id= "text-input">
<button id= "check-btn">Check </button>
<div id= "result">
</div>
<script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const textInput = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const result = document.getElementById("result");
const replaced = textInput.value.replace(/[^A-Za-z0-9]/g, "")
checkButton.addEventListener("click", () => {
if (textInput.value === ""){
alert("Please input a value")
} else if (textInput.value.length === 1) {
result.innerText = `${textInput.value} is a palindrome`
} else if (replaced === [...replaced].reverse().join("")){
result.innerText = `${textInput.value} is a palindrome`
} else {
result.innerText = `${textInput.value} is not a palindrome`
}
});
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker