i’ve tried multiple solutions from other people who had the same problem but nothing worked
<!DOCTYPE html>
<html lang="en">
<head>
<title>Palindrome Checker</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css"></link>
</head>
<body>
<h1>Is it a Palindrome?</h1>
<!--Main function of the site-->
<div id="result">
<p class="instruction">Enter in text to check for a palindrome:</p>
<div class="button-input">
<input type="text" id="text-input"></input>
<button id="check-btn">Check</button>
</div>
<div id="result-text">
</div>
</div>
<div class="PalExpl">
<p class="ExplText"> A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing. </p>
</div>
<!--JS code tag-->
<script src="script.js"></script>
</body>
</html>
const resultText = document.getElementById("result-text");
const buttonCheck = document.getElementById("check-btn");
const inputElement = document.getElementById("text-input");
/*Get the text inside the input*/
function storeInputText(){
/*Turn the text to lower case*/
const newLowerText = inputElement.value.toLowerCase();
/*Remove panctuation, space*/
const newText = newLowerText.replace(/[^a-zA-Z0-9]/g, "");
return newText;
}
/*Check if text is a palindrom*/
function isPal(text){
let isPalindrom = true;
let letterRight = text.length - 1;
let letterLeft = 0;
const middle = Math.floor(text.length / 2);
while(isPalindrom && letterLeft <= middle){
isPalindrom = text[letterLeft] == text[letterRight]
letterRight--;
letterLeft++;
}
return isPalindrom
}
/*Write the result of isPal*/
buttonCheck.addEventListener("click",() => {
const originaleText = inputElement.value;
const text = storeInputText();
if (originaleText == ""){
alert("Please input a value");
}else if(isPal(text)) {
resultText.textContent = `${originaleText} is a palindrome`;
}else{
resultText.textContent = `${originaleText} is not a palindrome`;
}
inputElement.value = "";
})