Run js function n times

I have a number counter script.

var $findme = $('#numbers');
var exec = false;

function Scrolled() {
  $findme.each(function() {
    var $section = $(this),
      findmeOffset = $section.offset(),
      findmeTop = findmeOffset.top,
      findmeBottom = $section.height() + findmeTop,
      scrollTop = $(document).scrollTop(),
      visibleBottom = window.innerHeight,
      prevVisible = $section.prop('_visible');

    if ((findmeTop > scrollTop + visibleBottom) ||
      findmeBottom < scrollTop) {
      visible = false;
    } else visible = true;

    if (!prevVisible && visible) {
      if (!exec) {
        $('.fig-number').each(function() {
          $(this).prop('Counter', 0).animate({
            Counter: $(this).text()
          }, {
            duration: 2000,
            step: function(now) {
              $(this).text(Math.ceil(now));
              exec = true;
            }
          });
        });
      }
    }
    $section.prop('_visible', visible);
  });

}


function Setup() {
  var $top = $('#top'),
    $bottom = $('#bottom');

  $top.height(500);
  $bottom.height(500);

  $(window).scroll(function() {
    Scrolled();
  });
}
$(document).ready(function() {
  Setup();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hww-whyus-item-num" id="numbers"> <span>0</span> <span class="fig-number">9</span> </div>

I need to add function to repeat count ‘n’ times: e.g. count starts from 00 to 05 and repeat once again from 00 to 05 three times. Or it can be the random numbers but the most important is the final number – I need to have ability to create animation with changing numbers but I need to control the final number and total time of the animation.

125 thoughts on “Run js function n times”

  1. I like the helpful info you provide in your articles. I’ll bookmark
    your weblog and check again here regularly. I’m quite certain I’ll learn a lot
    of new stuff right here! Best of luck for the next!

    Reply
  2. Pingback: keto bread crumbs
  3. Awesome blog! Is your theme custom made or did you download
    it from somewhere? A theme like yours with a few simple adjustements would really make my blog stand out.
    Please let me know where you got your theme.

    Many thanks

    Reply
  4. Excellent blog here! Also your web site loads up fast! What host are
    you using? Can I get your affiliate link to your host? I
    wish my site loaded up as quickly as yours lol

    Reply
  5. Good day! Would you mind if I share your blog with my facebook group?
    There’s a lot of people that I think would really appreciate your content.
    Please let me know. Thanks

    Reply
  6. Wonderful items from you, man. I’ve remember your stuff previous to and you’re just too wonderful.
    I actually like what you’ve got here, certainly like what you are stating and the way wherein you assert it.

    You are making it entertaining and you still take care
    of to stay it wise. I can’t wait to learn far more from you.
    This is really a great website.

    Reply
  7. Pingback: buy lumigan
  8. Pingback: molnopiravir
  9. Pingback: molnupirivir
  10. Pingback: nolvadex 20mg

Leave a Comment