# Repeat a Function x times? - Crazy Animation

**URL:** https://forum.kirupa.com/t/repeat-a-function-x-times-crazy-animation/191911
**Category:** Uncategorized
**Created:** [June 23, 2006, 9:14pm UTC](https://forum.kirupa.com/t/repeat-a-function-x-times-crazy-animation/191911 "2006-06-23T21:14:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jjmancini](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jjmancini](https://forum.kirupa.com/u/jjmancini)
#### Post date: [June 23, 2006, 9:14pm UTC](https://forum.kirupa.com/t/repeat-a-function-x-times-crazy-animation/191911/1 "2006-06-23T21:14:53Z")

</div>

Hey Everyone!

I am trying to repeat a function x number of times. How do I go about doing that?

Here is the function:

```auto
function dance(){
    var animspeed = .4;
    var back = 0;
    var delay = (animspeed);
    var delay1 = (animspeed*2);
    var delay2 = (animspeed*3);
    
    body.slideTo(124,304, animspeed, "easeOutSine");
    //lowerbody down
    body.lowerbody.rleg.rthigh.rotateTo(-30,animspeed,"easeInOutSine");
    body.lowerbody.rleg.rthigh.rfoot.rotateTo(40,animspeed,"easeInOutSine");
    body.lowerbody.lleg.lthigh.rotateTo(30,animspeed,"easeInOutSine");
    body.lowerbody.lleg.lthigh.lfoot.rotateTo(-40,animspeed,"easeInOutSine");
    //upperbody flail
    body.upperbody.rarm.rotateTo(-70,animspeed,"easeInOutSine");
    body.upperbody.rarm.rhand.rotateTo(-30,animspeed,"easeInOutSine");
    body.upperbody.larm.rotateTo(70,animspeed,"easeInOutSine");
    body.upperbody.larm.lhand.rotateTo(30,animspeed,"easeInOutSine");
    
    
    //AND BACK!
    body.slideTo(124,300, animspeed, "easeOutSine", delay);
    body.lowerbody.rleg.rthigh.rotateTo(back,animspeed,"easeInOutSine", delay);
    body.lowerbody.rleg.rthigh.rfoot.rotateTo(back,animspeed,"easeInOutSine", delay);
    body.lowerbody.lleg.lthigh.rotateTo(back,animspeed,"easeInOutSine", delay);
    body.lowerbody.lleg.lthigh.lfoot.rotateTo(back,animspeed,"easeInOutSine", delay);
    
    body.upperbody.rarm.rotateTo(back,animspeed,"easeInOutSine", delay);
    body.upperbody.rarm.rhand.rotateTo(0,animspeed,"easeInOutSine", delay);
    body.upperbody.larm.rotateTo(back,animspeed,"easeInOutSine", delay);
    body.upperbody.larm.lhand.rotateTo(back,animspeed,"easeInOutSine", delay);
}

```

How could I repeat that function x number of times if I use an on(mousePress) as my event?

Thanks!
