Closed tkentor closed 9 years ago
Can you show some code?
var incorrect = 0;
var correct = 0;
if (currentQuestion == 1) {
$("#jack").on("click", (function(){
$("#jack").attr("src", "farmer.png")
incorrect ++;
console.log(incorrect, "incorrect")
}));
$("#lucille").on("click", (function(){
$("#lucille").attr("src", "farmer.png")
incorrect ++;
console.log(incorrect, "incorrect")
}))
$("#cartman").on("click", (function(){
$("#cartman").attr("src", "farmer.png")
incorrect ++;
console.log(incorrect, "incorrect")
}))
$("#donald").on("click", (function(){
$("#donald").attr("src", "toilet.png")
correct ++;
console.log(correct, "correct")
}))
}
if (currentQuestion == 2) {
$("#jack").on("click", (function(){
$("#jack").attr("src", "farmer.png")
incorrect += 1;
console.log(incorrect, "incorrect")
}));
$("#lucille").on("click", (function(){
$("#lucille").attr("src", "toilet.png")
correct += 1;
console.log(correct, "correct")
}))
$("#cartman").on("click", (function(){
$("#cartman").attr("src", "farmer.png")
incorrect += 1;
console.log(incorrect, "incorrect")
}))
$("#donald").on("click", (function(){
$("#donald").attr("src", "farmer.png")
incorrect += 1;
console.log(incorrect, "incorrect")
}))
}
Is your project1 repo up to date? I'm cloning it down so I can look at it as a whole
Yeah it is, thanks
Can you show the text of the error you were getting?
So I'm not seeing any correct is undefined
or incorrect is undefined
which is there error you'll see when a variable is out of scope. The problem I'm seeing is the issue with the event listeners on old questions sticking around so on question two for example, clicking Trump will increment correct with the event listener from question one and then increment incorrect with the event listener attached on question two.
John's on his way!
I tried creating a variable that recorded clicks for each question. I expected the variable to continue counting for each question, but it was out of scope. I'm not sure how I get the counter to continue through the entirety of my game.