Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I'm making a website to annoy my friend and there is a download page. I would like a pseudo download counter, where it says: Downloaded (var) times!

I was wondering how to add numbers to the value after a specified delay in milliseconds.

For example, it would go
JavaScript
Downloaded 1 times!

Then the var would change to 2 (if it increased by 1 per amount of milliseconds) and so on, but only increased after the specified delay time.

Please refrain from using increment, because I might want to be able to change the value it increases by as well as the delay in milliseconds.

Please add comments to the code where the delay time is set, and where the value it increases by is.
Posted
Updated 7-Aug-15 15:23pm
v2

1 solution

Nevermind, I found the answer. I'll write it here for my and anyone else's reference:

<p>Downloaded <span id="number">0</span> times!</p>

<script type="text/javascript">
var i = 0; // Value starts off at zero
function increment() {
i++; // Change to i += [yourvalue] for any increase other than 1
document.getElementById('number').innerHTML = i;
}
setInterval('increment()', 2000); // Increments every 2 seconds
</script>
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 8-Aug-15 5:59am    
How could you self-accept it as a "solution"? This is nothing but abuse, both code and your post.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900