Javascript run a function inside a loop every x iterations

javascript

Solution

Instantiate a counter variable that increments every time anim() is called. When

counter % a === 0

Then you run this.appendEnd()

Problem

I have a variable of unknown value, it will be an integer. For this sake, lets say `var a = 3;` I have a function that is called continuously: ``` var a = 3; function anim() { left = parseInt(galleryInner.css('left'), 10); if(Math.abs(left) >= (galleryItem.length * galleryItem.width())){ galleryInner.css('left', 0); } galleryInner.animate({left: '-=20' }, 200, anim); that.appendEnd(); } ``` I'd like run this.appendEnd() only every 3 times, because `a === 3`. How can I do this?

Original source