I'm trying to program some buttons to light up and play a sound in the order of numbers from a random array I've generated, I'm changing the color to a lighter color than changing it back to the original in order to make them light up. Some of the time this works and then some of the time the buttons don't go back to the original color and I'm not sure why, I can't find a pattern to it. Can anyone see what I'm doing wrong with my code?
var turn = 19;
var b = 0;
function flash(button, light) {
button.addClass(light).delay(500).queue(function(){button.removeClass(light);})
}
function lightUp() {
switch (game[b]) {
case 1:
one.play();
flash($("#1"),"onelit");
break;
case 2:
two.play();
flash($("#2"),"twolit");
break;
case 3:
three.play();
flash($("#3"),"threelit");
break;
case 4:
four.play();
flash($("#4"),"fourlit");
break;
}
b++;
if (b < turn) {
setTimeout(lightUp, 2000);
}
}