Slow iterations? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Slow iterations?

Is there a way to have it slowly change the color of the texts? https://code.sololearn.com/WltGEPLlYF2I/?ref=app

12th Jul 2018, 8:38 PM
Daniel Cooper
Daniel Cooper - avatar
8 Answers
+ 2
https://stackoverflow.com/questions/1183872/put-a-delay-in-javascript
12th Jul 2018, 8:48 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
Use this... for(var x = 0; x < testOne.length; x++){ setTimeout(function(){ testOne[x].style.color = "blue" testOne[x].innerHTML = "Blue"; }, (x + 1) * 1000); } PS: I de-capitalised TestOne. You should not start variables with capitals, since older browsers may think they are a prototype like String or Array. Same with functions.
13th Jul 2018, 12:52 AM
James
James - avatar
0
There's no possible way to slowly do so, because the JS code runs immediately you click the button, so the color changes immediately
12th Jul 2018, 8:47 PM
Dlite
Dlite - avatar
0
Daniel Cooper You can do it in pure CSS with transition property. At example add .Test{ transition: color 2s; } into CSS tab and you will see 😉
12th Jul 2018, 9:36 PM
KrOW
KrOW - avatar
0
D'lite Well, you can re-write the code however you want, but luckily I found a way. Look at the updated code. https://code.sololearn.com/WltGEPLlYF2I/?ref=app
12th Jul 2018, 10:49 PM
Daniel Cooper
Daniel Cooper - avatar
0
Problem solved? PS: You could shorten your code with a loop, instead of doing each of the three separately.
12th Jul 2018, 11:17 PM
James
James - avatar
0
James Could you provide an example?
13th Jul 2018, 12:10 AM
Daniel Cooper
Daniel Cooper - avatar
0
James I only do it on Sololearn because OCD xD
13th Jul 2018, 5:42 AM
Daniel Cooper
Daniel Cooper - avatar