Can some pls explain this else statement to me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can some pls explain this else statement to me

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"; } }

9th Jul 2018, 4:22 PM
Falodun Ebenezer Tosin
3 Answers
+ 1
It adds 1 to "pos" and adds a CSS attribute to #box with the "pos" in pixels.
9th Jul 2018, 10:12 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 7
firstly we set pos to one. then select element with id box. then me use setIterval function i.e call a function after some time given by user. as in example its call move function .01 sec(1000= 1 second). and in our function move. their is condtion that check if our pos value is 150 or more than then perform clearInterval function ( clear function is used to stop setInterval ) and in else if we don't reach at 150 then add 1 into position and also add left 1pixel to position of box. hope you understand
12th Jul 2018, 8:47 AM
Sunny
Sunny - avatar
0
thanks a lot
18th Jul 2018, 11:01 AM
krishna reddy
krishna reddy - avatar