Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  96] [ 4]  / answers: 1 / hits: 16768  / 8 Years ago, tue, april 19, 2016, 12:00:00

so I am making a simon says game. This function displays the current sequence. The problem with it right now is that it doesn't really go in a nice sequence, it kind of does everything at once. Say the colors are blue, red, and yellow, they will all go off at the same time rather than in sequence. How can I fix this?



var displaySequence = function(){
compSequence.forEach(function(color){
$(# + color).fadeTo(300, 0.5).fadeTo(300, 1.0);
})
}

More From » jquery

 Answers
38

A none jQuery solution. You will need to use the array index to give the illusion of waiting between each call, however each function has ran already. What will happen is: show color 1 in 1 second, show color 2 in 2 seconds...



var displaySequence = function(){
compSequence.forEach(function(color, index){
setTimeout(function(){
$(# + color).fadeTo(300, 0.5).fadeTo(300, 1.0);
},
1000 * index);
})
}


adjust the 1000 * index to change the delay.


[#62496] Sunday, April 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;