Hello everyone, i’m stuck doing my first project in js. any guidance is welcome.
My problem is that when I press the button, nothing happens, I don’t know where to look for debugging.
My code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-80">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Palindrome Checker</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Karla:ital,wght@0,200..800;1,200..800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
</head>
<body>
<main>
<div class="main-container">
<h2>< 💻milan web developer ></h2>
<h1>Is it a Palindrome?</h1>
<div class="palindrome-container">
<form id="text-input-form">
<label for="text-input" class="label-text">Enter in text to check for a palindrome:</label>
<div>
<input type="text" id="text-input" placeholder="Your word"required>
<button type="submit" class="check-btn" id="check-btn">Check</button>
</div>
</form>
</div>
<div class="result-container hidden" id="result">
</div>
<div class="palindrome-definicion">
<p class="definicion-p"><span role="img" aria-label="light-bulb">💡</span>A <i>palindrome</i> is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
</div>
</div>
</main>
</body>
<script src="./script.js"></script>
</html>
const textInput = document.getElementById('text-input');
const button = document.getElementById('check-btn');
const result = document.getElementById('result');
function clean (str) {
const regex = /\W_/g;
return str.match(regex);
}
const input = textInput.value;
const string = clean(input);
const lowerString = string.toLowerCase();
const copyLowerString = [...lowerString];
const reverse = copyLowerString.split('').reverse().join('');
function palindrome() {
if (textInput.value === "") {
alert("Please input a value")
} else if(reverse === lowerString){
result.classList.remove('hidden');
result.innerHTML = `<strong>${textInput.value}</strong> is a palindrome`;
} else {
result.classList.remove('hidden');
result.innerHTML = `<strong>${textInput.value}</strong> is not a palindrome`;
}
}