RinSupreme RinSupreme - 1 year ago 64
jQuery Question

Summing a number recursively and displaying it

I searched for a solution to this problem quite a bit, but couldn't reach a solution. Would be great if someone can point me in the right direction.

Ok, so suppose there's a number :-


What I want to do is, add 0.001 (the same number) to it again and again ever second and also display the change dynamically.

So :-

second 1 :- 0.001
second 2:- 0.002
second 3 :- 0.003

This has to keep running for 1 hour and I should be able to see it's value changing dynamically on my web page. How can I achieve this? I did quite a research on using countup.js, but no result. I thought of a solution to use ajax, but this would cause a lot of load.
Whats the best that I can do here?

Answer Source

Is this what you want?
feel free to play with it

var c = 0.000;
var count = document.getElementById('count');
count.innerHTML = c;

// Creates the interval with the name interval
var interval = setInterval(function() {
  c += 0.001
  count.innerHTML = ("" + c).substring(0, 5);
}, 100) // 1/10 sec for demo

// Clear the interval after one hour
setTimeout(function() {
}, 1000) // one second for demo
counter: <span id="count"></span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download