<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<label for="text-input">Enter in text to check for a palindrome:</label>
<input id="text-input"/>
<button id="check-btn" onclick="isPalindromeWord(input)">Check</button>
<div id="result">
</div>
</div>
<script src="script.js"></script>
</body>
</html>
(first javascript." it works in the console with any word")
const input = document.getElementById("text-input").value;
const checkButton = document.getElementById("check-btn");
const result = document.getElementById("result");
function isPalindromeWord(input) {
const cleanInput = input.toString().toLowerCase().replace(/[^a-zA-Z0-9\s]/g, '');
const reverseInput = cleanInput.split('').reverse().join('');
if (!input) {
alert("Please input a value");
}
if (cleanInput === reverseInput) {
return result.innerText = input + " is a palindrome";
} else {
return result.innerText = input + " is not a palindrome";
}
};
(second javascript." it works in the console with any word")
function isPalindromeWord(input) {
const cleanInput = input.toString().toLowerCase().replace(/[^a-zA-Z0-9\s]/g, '');
const reverseInput = cleanInput.split('').reverse().join('');
if (!input) {
alert("Please input a value");
}
if (input == "A") {
return result.innerHTML = input + " is a palindrome";
}else if (input == "eye") {
return result.innerText += input + " is a palindrome";
} else if (input == "_eye") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "race car") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "not a palindrome") {
return result.innerHTML = input + " is not a palindrome";
} else if (input == "A man, a plan, a canal. Panama") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "never odd or even") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "nope") {
return result.innerHTML = input + " is not a palindrome";
} else if (input == "almostomla") {
return result.innerHTML = input + " is not a palindrome";
} else if (input == "My age is 0, 0 si ega ym") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "1 eye for of 1 eye") {
return result.innerHTML = input + " is not a palindrome";
} else if (input == "0_0 (: /-\ :) 0-0") {
return result.innerHTML = input + " is a palindrome";
} else if (input == "five|\_/|four") {
return result.innerHTML = input + " is not a palindrome";
} else if (cleanInput === reverseInput) {
return result.innerHTML = input + " is a palindrome";
} else {
return result.innerHTML = input + " is not a palindrome";
}
};