Skip to content

Instantly share code, notes, and snippets.

@AaronGoldsmith1
Created October 14, 2016 18:28
Show Gist options
  • Save AaronGoldsmith1/ba19cd48ab808dc1f8898a7ba802963a to your computer and use it in GitHub Desktop.
Save AaronGoldsmith1/ba19cd48ab808dc1f8898a7ba802963a to your computer and use it in GitHub Desktop.

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();
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment