Skip to content

Instantly share code, notes, and snippets.

@AaronGoldsmith1
Created October 14, 2016 18:27
Show Gist options
  • Save AaronGoldsmith1/8c50d5cba641a6593748ccb035d5600d to your computer and use it in GitHub Desktop.
Save AaronGoldsmith1/8c50d5cba641a6593748ccb035d5600d to your computer and use it in GitHub Desktop.
Project 1 Code Review Gist

This function initiates the winning indication by flashing all the colored sections four times.

//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