Reputation: 73
So I had this working last night, its a 10 questions quiz. I did a few revisions today, and now when I click to check the answer, I've lost the functionality that would display in the jumbotron if the answer was correct or not. The continue to next question still deletes and repopulates the list. Just the button to check the question answer is broken. Here's the jsFiddle link:
Upvotes: 0
Views: 25
Reputation: 2456
The issue has to do with your i
value not being valid in the listener callback block. You can resolve this by using your currentQuestion
value instead, like so:
$('#submit').on('click', function() {
var answer = $('input[name="1"]:checked').val();
if (answer == questionsArray[currentQuestion]['answer']) {
correctAnswers++;
$('.jumbotron').html(answer + "?<br><br> That's correct! You have " + correctAnswers + " out of 10 correct!");
} else {
$('.jumbotron').html(answer + "? <br><br> Oh dear, that's so so wrong! You have " + correctAnswers + " out of 10 correct");
}
return false;
});
Upvotes: 1