I assigned variables in an if-statement that is ALWAYS supposed to run when the code first starts, as seen here:
let started = false;
$(document).on("keypress", function(){
if (!started){
let counter = 0;
started = true;
}
console.log(counter++);
});
Yet I get an error that counter, in the console.log(), is undefined. Yet every time the code is executed, 'started' will always be false, meaning 'counter' will always be defined and set to 0. I can't possibly see how console.log() is executed when the definition for 'counter' isn't. I don't see what I'm doing wrong.
Aucun commentaire:
Enregistrer un commentaire