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 8813513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:52:14+00:00 2026-06-14T03:52:14+00:00

I have the following code for my simple stopwatch, which only counts the number

  • 0

I have the following code for my simple stopwatch, which only counts the number of seconds with no formatting whatsoever:

function countDown(from, interval, callback) {
   interval = interval || 1000;
   var current = 0;
   var onCount = function() {
      current++;
      if (current <= from) {
         callback(current, from);
         setInterval(onCount, interval);
      }
   }

   onCount();
}

This is called with an onclick, with the following code:

countDown(600, 1000, function(current, from) {
   time_out.innerHTML = current;
});

Putting in a console.log(current), I can see two problems. First, though it does go through every number, it seems to get faster and faster, by powers of two. In the output div, the first tick will be 1, the second will be 2, the third will be 4, the fourth will be 8, and so on. Furthermore, it does not actually stop counting when it hits 600, even though it stops updating the div. What did I do wrong here?

  • 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-14T03:52:15+00:00Added an answer on June 14, 2026 at 3:52 am

    You use setInterval which will call the callback at a set interval every time the function is called, resulting many many calls to countDown()

    Maybe you wanted to use the setTimeout function instead, which will only call the function once after the delay.

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

Sidebar

Related Questions

I have the following very simple code snippet which is loaded from a separate
I have the simple following code, which is working in a ruby (not rails)
I have the following code which creates a simple window with two buttons which
I have the following simple code: import urllib2 import sys sys.path.append('../BeautifulSoup/BeautifulSoup-3.1.0.1') from BeautifulSoup import
I have the following simple code: The model: function get_last_ten_entries() { $this->db->get('property'); } controller:
I have the following simple code (see below) I copied from a book. But
I'm migrating from Symfony 2.0 to Symfony 2.1. I have the following simple code
I have the following simple code: var tabs = null; function addTab(id, title, data)
I have following code which on save from the admin area creates a duplicate
I have the following code which I am using for making a simple template

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.