Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I recently created a palindrome checker using HTML and JavaScript in Visual Studio Code, and it works perfectly there. However, when I copied and pasted the exact same code into the freeCodeCamp environment, it fails to function as expected.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Palindrome Checker</title>
</head>
<body>

    <input type="text" id="text-input" placeholder="Enter text">
    <button id="check-btn">Check</button>
    <p id="result"></p>
    </body>
    </html>
/* file: styles.css */

/* file: script.js */
const input = document.getElementById('text-input');
        const button = document.getElementById('check-btn');
        const result = document.getElementById('result');

        button.addEventListener("click", () => {
            if (input.value === '') {
                alert("Please input a value");
                return;
            }

            const regex = /[^a-zA-Z0-9]/g; 
            const newText = input.value.replace(regex, '').toLowerCase();

            const getPalindrome = (value) => {
                const reversed = value.split('').reverse().join('');
                return reversed;
            };

            if (newText === getPalindrome(newText)) {
                result.innerText = `${input.value} is a palindrome.`;
            } else {
                result.innerText = `${input.value} is not a palindrome.`;
            }
        });

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

Your checker might be ok. But if it does not follow some of the instructions listed in the checkbox tasks, you’ll have some problems.


Its working . Sometimes, in backend server of freecodecamp takes load of multiple request but try now it will work.

in what ways it fails to function as expected?

1 Like

like when i enter a text. there is no output.
no alert button and no change in the innerText of result

I am not sure you have linked the js file to the html file, maybe add that

1 Like

Oh thats the problem. i didnt include it. Thank you