Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:56:24+00:00 2026-06-02T05:56:24+00:00

In this article , the following function is given to perform an operation x

  • 0

In this article, the following function is given to perform an operation x times with setInterval()

setIntervalX(function () {
    animateColor();
    //or something
}, 3000, 4);

function setIntervalX(callback, delay, repetitions) {
    var x = 0;
    var intervalID = window.setInterval(function () {

        callback();

        if (++x === repetitions) {
            window.clearInterval(intervalID);
        }
    }, delay);
}

what does the callback() do here? I’m trying to do a function after the specified number of repetitions is complete. but this

setIntervalX(function () {
    animateColor();
}, 3000, 4, function(){

completeFunction();

});

does not work. Perhaps that syntax is very wrong. I was under the impression that using jquery, you could string together functions like that..

Much grateful for any insight. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:56:27+00:00Added an answer on June 2, 2026 at 5:56 am
    function setIntervalX(func, delay, times, callback) {
        if (times > 0) {
            setTimeout(function() {
                func.apply(arguments.callee);
                setIntervalX(func, delay, --times, callback);
            }, delay);
        } else {
            callback.apply(this);
        }
    }
    
    setIntervalX(function() {
        document.write('ping!<br />');
    }, 1000, 5, function() {
        document.write('Finished!<br />');
    });
    

    ​

    I personally prefer the setTimeout method… but that is just me. give this a shot and see if it works. demo

    Ahh it appears I have misread you’re entire post… so Tobias is correct in his reasoning for your question. mine is an example of what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this article: http://www.lunametrics.com/blog/2011/12/01/automatic-cross-domain-tracking-revisited/ which leads me to put the following in
I've been following this article to display ActiveRecord data in QtRuby. I've copied the
Considering this article Developing a MVC component for Joomla , following is the code
I was reading this article and I came across the following definition (in qglobal.h
I have seen the following links before posting this question http://www.devx.com/wireless/Article/40792/1954 Saving Android Activity
I want to know something about this article In order to create custom post
I implement this function : GetSystemPowerStatusEx & GetSystemPowerStatusEx2 according to this article on MSDN
Given the php code: $xml = <<<EOF <articles> <article> This is a link <link>Title</link>
I read this article recently , and I tried overriding the libc printf function
This article from Microsoft details how to implement transport security with an anonymous client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.