javascript - I want to create a countdown from 50 down to 1, but I don't want to count down the same amount of time between each number -


i want create countdown 50 down 1, don't want count down same amount of time between each number.. if 50 seconds, don't want count down number every second. i'm trying create countdown bit of randomness maybe takes 2 secs next number or .5 seconds. i'm trying way down last 10 seconds slow down bit more before counter stops @ number 1.

heres html have:

<span id="count">50</span> 

the javascript:

sec = 50;  interval = setinterval(function () {   sec--;   document.getelementbyid('count').innerhtml = sec;    if (sec == 1) {     clearinterval(interval);   }  }, 1000);  

jsfiddle: http://jsfiddle.net/avrpg/

how slow down last 10 seconds , how add bit of randomness it?

var sec = 50;  function execute() {   document.getelementbyid("count").innerhtml = sec; }  (function loop() {   if(sec-- == 0) {     return // stop when reach 0   }    settimeout(function() {     execute();     loop()    }, math.round(math.random() * 1e3) + (sec <= 10 ? 2e3 : 500))                 // random 1000 or 0  +  2000 if sec <=10 or 500 otherwise })(); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -