Tell us what’s happening:
Hello,
I’m unsure what’s wrong with my code. Whenever I click the “Check” button, nothing happens.
I’m also getting the code error:
[TypeError: Cannot read properties of undefined (reading ‘trim’)]
I’ve changed every part of the code, used trim, removed it, splitting the code into various functions. The issue is always the same…
This is the code I ended up with, I’m sure there are plenty of misses as I’ve changed it a dozen times.
Would appreciate any help!
Thanks!
### Your code so far
```html
<!-- file: index.html -->
<!DOCTYPE HTML><html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" href="styles.css"/>
<title>Palindrome Checker</title>
</head>
<body>
<h1 id="title">Is it a Palindrome?</h1>
<fieldset id="checker">
<div id="checker-div">
<p>Enter in text to check for a palindrome:</p>
<input type="text-input" id="text-input"></input>
<button id="check-btn">Check</button>
</div>
<span id="result"> <div id="result"><p id="result"></p></div></span>
</fieldset>
<script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const checkBtn = document.getElementById('check-btn');
const inputText = document.getElementById('text-input');
const result = document.getElementById('result')
checkBtn.addEventListener ("click", checkPal)
function palindrome (inputText){ const palText = /[\W_]/g;
const pal = inputText.trim().toLowerCase().replace(palText, '');
const reversePal = pal.split('').reverse('').join('');
const isPalindrome = pal === reversePal;
return isPalindrome;;};
function checkPal (){
if (inputText.value === null) {alert("Please input a value")}
else
{if (palindrome === true){
result.style.display = "block";
result.innerHTML = `${pal} is a palindrome`;
}
else if (palindrome === false ) {
result.style.display = "block";
result.innerHTML = `${pal} is not 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/129.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker