Simon says | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Simon says

I need to make this cool game using pure javascript (no jQuary). I have a problem make the button's opacity change and go back to normal. I have tried to change it using setTimeout but Its stuck on the new opacity I gave. Thanks alot!

13th Mar 2017, 1:40 PM
Zohar Revivo
Zohar Revivo - avatar
3 Answers
+ 9
create variable with a value of 0 use setInterval(function, 1000) to invoke a function which will add 1 to your var if var is greater than 0 you give the button the new opacity if var is greater than 2 give the button the old opacity, use clearInterval and set the var back to 0
13th Mar 2017, 2:33 PM
The Coding Sloth
The Coding Sloth - avatar
0
How I can see your code in order to help?
13th Mar 2017, 2:22 PM
Mohieddin Almasri
0
Ok I found this code: function showMoves() { var i = 0; var moves = setInterval(function(){ playGame(r_array[i]); i++; if (i >=r_array.length) { clearInterval(moves); } }, 600) } function playGame(field) { document.getElementById(field).style.opacity="0.3"; setTimeout(function(){ document.getElementById(field).style.opacity="1"; }, 1000); } It works just fine but still I don't understand 100% why this one is good.
13th Mar 2017, 2:46 PM
Zohar Revivo
Zohar Revivo - avatar