JavaScript JavaScript Countdown clock not automattically counting down javascript countdown clock code,javascript countdown clock,javascript countdown clock

Below is my JS and then my HTML . I cannot figure out why my countdown clock doesn't automatically count down. You must refresh every second to see the correct amount of time left. Any ideas? BTW this is for a Christmas countdown website I am working on.

var Countdowns = function(end, elements, timer, callback) {
  var _seconds = 1000,
    _minutes = _seconds * 60,
    _hours = _minutes * 60,
    _days = _hours * 24,

    end = new Date(end)
  timer,

  calculate = function() {
    var now = new Date(),
      remaining = end.getTime() - now.getTime(),
      data;


    if (isNaN(end)) {
      console.log('Invalid date/time')
      return;
    }

    if (remaining <= 0) { // clear timer
      clearInterval(timer);
      // callback
      if (typeof callback === 'function') {
        callback()
      }
    } else {
      if (!timer) {
        timer = setInterval(calculate, _seconds);
      }
      data = {
        'days': Math.floor(remaining / _days),
        'hours': Math.floor((remaining % _days) / _hours),
        'minutes': Math.floor((remaining % _hours) / _minutes),
        'seconds': Math.floor((remaining % _minutes) / _seconds),
      }

      if (elements.length) {
        for (x in elements) {
          var x = elements[x];
          data[x] = ('00' + data[x]).slice(-2);
          document.getElementById(x).innerHTML = data[x];
        }
      }
    }






  };
  calculate();
}
<!DOCTYPE html>
<html>

<head>
  <title>Countdowns</title>
</head>

<body>
  <span id="days">00</span>
  <span id="hours">00</span>
  <span id="minutes">00</span>
  <span id="seconds">00</span>

  <script src="Countdowns.js"></script>
  <script>
    var callbackfunction = function() {
      console.log('Done!')
    }
    Countdowns('12/25/2015 00:00:00 AM', ['days', 'hours', 'minutes', 'seconds']);
    callbackfunction);
  </script>
</body>

</html>
Answer:1

You have a couple of minor errors. Try this:

var Countdowns = function(end, elements, timer, callback) {
  var _seconds = 1000,
    _minutes = _seconds * 60,
    _hours = _minutes * 60,
    _days = _hours * 24,

    end = new Date(end)
  timer,

  calculate = function() {
    var now = new Date(),
      remaining = end.getTime() - now.getTime(),
      data;


    if (isNaN(end)) {
      console.log('Invalid date/time')
      return;
    }

    if (remaining <= 0) { // clear timer
      clearInterval(timer);
      // callback
      if (typeof callback === 'function') {
        callback()
      }
    } else {
      if (!timer) {
        timer = setInterval(calculate, _seconds);
      }
      data = {
        'days': Math.floor(remaining / _days),
        'hours': Math.floor((remaining % _days) / _hours),
        'minutes': Math.floor((remaining % _hours) / _minutes),
        'seconds': Math.floor((remaining % _minutes) / _seconds),
      }

      if (elements.length) {
        for (x in elements) {
          var x = elements[x];
          data[x] = ('00' + data[x]).slice(-2);
          document.getElementById(x).innerHTML = data[x];
        }
      }
    }
  };
  calculate();
};

var callbackfunction = function() {
  console.log('Done!')
}
Countdowns('12/25/2015 00:00:00 AM', ['days', 'hours', 'minutes', 'seconds']);
callbackfunction();
<!DOCTYPE html>
<html>

<head>
  <title>Countdowns</title>
</head>

<body>
  <span id="days">00</span>
  <span id="hours">00</span>
  <span id="minutes">00</span>
  <span id="seconds">00</span>
  <script src="Countdowns.js"></script>
</body>

</html>
Answer:2

replace callbackfunction); with callbackfunction();

Answer:3

I'd like to replace all blocked ads (for users with adblock) with an image politely asking to have the site white-listed. This code wasn't written by me at all- it's taken from a site that I can't ...

I'd like to replace all blocked ads (for users with adblock) with an image politely asking to have the site white-listed. This code wasn't written by me at all- it's taken from a site that I can't ...

async function test() { const res = await fetch('https://www.easy-mock.com/mock/5c6d317e8d040716434d0a5b/reading/category/homeSmallCategory'); console.log(res) // data return res; } ...

async function test() { const res = await fetch('https://www.easy-mock.com/mock/5c6d317e8d040716434d0a5b/reading/category/homeSmallCategory'); console.log(res) // data return res; } ...

I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...

I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...

  1. access google search history
  2. access google search console
  3. access google search data
  4. access google search api
  5. access google search box
  6. access my google search history
  7. can't access google search
  8. cannot access google search engine
  9. python access google search
  10. access vba google search
  11. access google voice search
  12. how to access google search settings
  13. how to access google search trends
  14. how to access google search
  15. cbs all access - google search
  16. how to access google search history on ipad
  17. how to access google search results
  18. google access music search history
  19. give access to google search console
  20. grant access to google search console

Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...

Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...

  1. firebase query documents