Tell us what’s happening:
I feel like my code right. when i run it on live server using vs code, the checker itself works fine. when i try it in freecode camp environment I keep getting the error that checkpalidrome is undefined.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>freeCodeCamp</h2>
<h1>Is it a Palindrome?</h1>
<p>Enter in the text to check for a palidrome:</p>
<input id="text-input"/>
<button id="check-btn">Check</button>
<p id="result"></p>
<p>A <em>palindrome</em> is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
<script src="index.js"></script>
</body>
</html>
/* file: script.js */
document.getElementById("check-btn").addEventListener("click", checkPalindrome);
function checkPalindrome() {
const input = document.getElementById("text-input").value;
const cleanedInput = input.toLowerCase().replace(/[^a-zA-Z0-9]/g, "");
// Reverse the string by splitting into an array, reversing, and joining back
const reversedInput = cleanedInput.split("").reverse().join("");
if (cleanedInput === reversedInput) {
document.getElementById("result").innerText = input + " is a palindrome.";
} else {
document.getElementById("result").innerText = input + " is not a 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/130.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker