I've been trying to figure out on the how to do an increment each time the button is clicked after the random numbers matches, or doesn't match.
Basically, if the numbers matched, a counter for matched will go up. Same goes for mismatched numbers.
But currently, the counter will only go up once and only once.
jQuery:
$(document).ready(function(){
var a;
var b;
display();
displayInt();
function displayInt(){
var disInt;
disInt = setInterval(display, 2000);
}
function display() {
a = Math.floor((Math.random()*3)+1);
$("#number1").html(a);
b = Math.floor((Math.random()*3)+1);
$("#number2").html(b);
}
function addScore(){
var correct;
var wrong;
correct=0;
wrong=0;
if (a == b){
correct++;
$("#correctScore").html(correct);
}else{
wrong++;
$("#wrongScore").html(wrong);
}
}
$('input[type="button"]').click(function() {
a = $("#number2").html();
b = $("#number1").html();
addScore();
});
});
Aucun commentaire:
Enregistrer un commentaire