How to make box move right and left endlessly?
When clear interval is set it just doesn't work anymore.. how can I stop it from running the animation to the right and then go to left and so on endlessly? //calling the function in window.onload to make sure the HTML is loaded window.onload = function() { var pos = 0; //our box element var box = document.getElementById('box'); var t = setInterval(move, 10); function move() { if(pos >= 150 ) { var y = setInterval(moveLeft, 10); clearInterval(t); } else { pos +=1; box.style.left = pos+'px'; } } function moveLeft() { pos--; box.style.right = pos+'px'; } }; https://code.sololearn.com/953/#js