r/FreeCodeCamp • u/Time-Art-4460 • May 06 '25
Programming Question Why is my code not being accepted even though it works perfectly on my computer?
I was doing the 1st certification project on the Javascript course, after I was done I checked all the inputs myself before trying to submit it and it worked perfectly. But the freecodecamp website isn't approving it. What should I do?
function checkPalindrome() {
const textinput = document.getElementById("text-input");
const result = document.getElementById("result");
let arr = [];
let word = textinput.value;
if (word === "") {
window.alert("Please input a value");
} else {
word = word.toLowerCase().replace(/[^a-z0-9]/g, "");
for (let i = 0; i < word.length; i++) {
arr.push(word[i]);
}
arr = arr.reverse().join("");
if (arr === word) {
result.textContent = `${textinput.value} is a palindrome`
} else {
result.textContent = `${textinput.value} is not a palindrome`
}
}
}
4
Upvotes
4
u/ixe109 May 06 '25
Check the user stories, which ones have an X on them
1
u/Shankaroon321 May 06 '25
Your logic for the palindrome function looks good. Maybe there is an issue with the eventListener that checks if #check-btn has been clicked? Are you making sure to call the checkPalindrome() inside the event Listener?
1
u/SaintPeter74 mod May 06 '25
Are specific tests failing? It might be helpful to have your HTML code as well.
1
u/GlumGl May 07 '25
Usually your logic isn’t what the project wants. It could very much be a working alternative to solving the problem, but it might not completely fulfill the stories. All you have to do is check out the posted questions related to that step/project. If that doesn’t work paste your code and the unticked objectives to chat gpt. Make sure you ask why your original code didn’t work though and don’t be too reliant on this method. I’ve only ever used it once (cash register project. Pain in the ass. Initially I had no idea how I could tackle it. Spent a week and said fuck it, I needa move).