Skip to content

Instantly share code, notes, and snippets.

@mstan
Created December 9, 2016 07:04
Show Gist options
  • Select an option

  • Save mstan/cd5cf377db6b3715061182656bc6749a to your computer and use it in GitHub Desktop.

Select an option

Save mstan/cd5cf377db6b3715061182656bc6749a to your computer and use it in GitHub Desktop.
var soundArr = ['A.wav', 'B.wav', 'C.wav', 'D.wav']; //Array of all of our sound files
var tempNum = 0; //Temporary number that is just used to figure out where we are
var buttonPressTime = 0; //In seconds, start as zero. This would be replaced with how long it would actually take
var buttonPress = function(buttonPressTime) { //Declare a function--not run--that does the following with the input of buttonPressTime
if(buttonPressTime < 1 ) { //if the value of buttonPressTime is less than 1 (second)
playSound(soundArr[tempNum]);
tempNum = tempNum + 1; //Take the variable tempNum, and set it equal to tempNum + 1 (current value, but one higher);
} else if (buttonPressTime >= 1) { //This is greater than 1s
tempNum = 0; //set the temporary variable back to zero (restart)
}
}
while(tempNum < soundArr.length) { //while our tempNum value is less than the value of soundArr.length (in this case, soundArr.length = 4 because there are four elements)
buttonPress(buttonPressTime); //Run the function buttonPress with an input of the buttonPressTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment