[Solved] I need help may someone please explain why my setinterval is acting goofy? [closed]


To make this more clear since you seem to be having some trouble: you redefined moved inside your interval, so every time it runs, it gets set back to 100.

You need to initialize that outside the interval.

function moveAllTriangles(){
    var spike = document.getElementById("spike");
    var moved = 100;

    function moveTriangle(){
        spike.style.left = (750 - moved) + 'px';
        moved++;  
    }

    var mg = setInterval(moveTriangle, 1125);
}

Also, setInterval() takes a function name or a closure, you don’t need to use a closure, just pass the name of the function you’ve already defined.

solved I need help may someone please explain why my setinterval is acting goofy? [closed]