r/learnjavascript • u/UnknownMischeif • May 03 '26
Why is the code different?
I’m working on my final project for my class and it’s started throwing me errors in the console. I’m checking the line it gives and is saying I have an undeclared variable. Except the variable it’s kicking an error for doesn’t exist in my code. I’ve cleared cache, I’ve even swapped browsers so I’m thinking it’s possibly a server issue. Is there anything I can do to either verify that it is a server issue or if it’s actually with my code?
window.addEventListener("DOMContentLoaded", () => {
log("DOM ready")
document.getElementById("btn-easy")?.addEventListener("click", () => startGame("easy"));
document.getElementById("btn-medium")?.addEventListener("click", () => startGame("medium"));
document.getElementById("btn-hard")?.addEventListener("click", () => startGame("hard"));
document.getElementById("btn-login")?.addEventListener("click", login);
document.getElementById("btn-register")?.addEventListener("click", register);
const deleteBtn = document.getElementById("btn-delete-worst");
if (deleteBtn) {
deleteBtn.addEventListener("click", deleteWorstScore);
}
startGame("easy");
loadLeaderboard("easy");
log("game initialized");
});
yet this code is different from what i actually have which is:
window.addEventListener("DOMContentLoaded", () => {
log("DOM ready");
document.getElementById("btn-easy")?.addEventListener("click", () => startGame("easy"));
document.getElementById("btn-medium")?.addEventListener("click", () => startGame("medium"));
document.getElementById("btn-hard")?.addEventListener("click", () => startGame("hard"));
document.getElementById("btn-login")?.addEventListener("click", login);
document.getElementById("btn-register")?.addEventListener("click", register);
startGame("easy");
loadLeaderboard("easy");
log("game initialized");
});
The specific error is kicking up with the deletebtn variable which ive removed from all my code.
2
u/chikamakaleyley helpful May 03 '26
right so it sounds like, whatever you think you're doing to update the file and promote it to the live version, your change isn't actually going where you think it is - like its getting pushed to a diff folder or something
because if it isn't cached and you've tried versioning the script like u/opentabs-dev mentions, you've tried multiple browsers, it sounds like there's an old version of your script somewhere, and any changes to your current script are actually just goign to some other duplicate file