I'm a newbie in JQuery, but I just can't find out why the if statement here doest work. You see in the code alert(a) and alert(timesRun) I put it there so i could test, if the variables did indeed count up as intended and they did.
Now is the problem: var a is determined by userinput and should make the clock stop when its equal to timesrun but the if statement seems not to work even when both alerts say: var a =12 and var timesrun is 12 the interval continues even though the if statement should have stopped it. Sorry if I'm being unclear or messy I am just at secondary school and not even native English speaker.
< script >
$(document).ready(function () {
$('#turnright1').click(function () {
var a = $("#nummr1").val();
var angle = 0;
var timesRun = 0;
var interval = setInterval(function () {
timesRun += 1;
alert(a);
alert(timesRun);
if (timesRun === a) {
clearInterval(interval);
}
angle += 3.6;
$('img[src^="Images/lockercenter.png"]').rotate(angle);
i++
}, 1000);
});
});
</script>