Help : ') Javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help : ') Javascript

var pos = 0; //our box element var box = document.getElementById("box"); var t = setInterval(move, 10); function move() { if(pos >= 150) { clearInterval(t); } else { pos += 1; box.style.left = pos+"px"; } } -------------------------------------------------------------- "(move, 10);"? for what this '10' ? why 10 ?

23rd Jul 2018, 5:19 AM
Zulfikar Ahmad
Zulfikar Ahmad - avatar
3 Answers
+ 3
You’re right
23rd Jul 2018, 5:33 AM
Toni Isotalo
Toni Isotalo - avatar
+ 2
Ahhhh, so that is duration.... Thanks Toni :D
23rd Jul 2018, 5:27 AM
Zulfikar Ahmad
Zulfikar Ahmad - avatar
+ 2
Actually, it moves 1px every 10ms. So: 10ms = 1px; 100ms = 10px; 1000ms (1 second) = 100px. Safe to say since it is 150px, it will be 1500ms or 1.5 seconds. This animation is 1.5 seconds in length.
23rd Jul 2018, 5:32 AM
Andre Daniel
Andre Daniel - avatar