Tell us what’s happening:
I can’t get my function to print ${textInput.value} is not a plaindrome it only prints is a plaindrome
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="eng">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Palindrome Checker</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main class="container">
<h1 class="title">Is it a plaindrome?</h1>
<div class="palindrome-form">
<input id="text-input" value-type="text"/>
<button id="check-btn" type="submit">Check</button>
<div id="result" class="hide"></div>
</div>
</main>
<script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const textInput = document.getElementById("text-input");
const checkBtn = document.getElementById("check-btn");
const result = document.getElementById("result");
function validateInput () {
if (textInput.value === "") {
return alert("Please input a value");
} else if (textInput.value === textInput.value.split().reverse().join()) {
return result.innerHTML = `${textInput.value} is a palindrome`;
} else {
return result.innerHTML = `${textInput.value} is not a palindrome`;
}
};
checkBtn.addEventListener("click", () => {
validateInput(textInput.value);
});
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker