This function initiates the winning indication by flashing all the colored sections four times, and is probably the most interesting bit of code in the app.
//all colored section flash 4 times in a row to signify the user has won
function userWin() {
winFlashes++;
for(var i = 0; i < 4; i++){
$colors.each(function(){
var color = $(this); //referencing all colored sections
var turnOnIn = 1000 * i;
var turnOffIn = turnOnIn + 500;
//0 : turn on 0, turn off in 500
//1 : turn on in 1000, turn off in 1500
//2 : turn on in 2000, turn off in 2500
//3: turn on in 3000, turn off in 3500
//turn on all colored sections
setTimeout(function(){
var colorName = getColorName(color);
lightUpButton(colorName, false); //Do not play section's sound
}, turnOnIn);
//turn off all colored sections
setTimeout(function(){
color.css('filter', 'brightness(100%)');
}, turnOffIn);
window.clearInterval(playerTimer);
});
}
$("#playerAlert").show();
}