Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help needed for event counter

    Hi - I am developing a birthing website and would like to include a counter that indicates how many babies have been born in the world in 2009. The global birth rates are 236 per minute or 3.94 per second. Can anybody help with a script that would be able to display this information.
    Thank you.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Here you are:-

    Code:
    <div id = "babies"></div>
    
    <script type = "text/javascript">
    
    var basisDate = new Date(2009,0,1).getTime();   // January 1st 2009
    
    function countBirths() {
    var now = new Date().getTime();
    var diff = (now - basisDate)/1000;  // seconds
    var births = (parseInt(diff * 3.94));  // 3.94 per second
    births = births.toString();
    births = addCommas(births);
    msg = "The number of babies born in the world during 2009 up to this moment is estimated to be:- "
    document.getElementById("babies").innerHTML = msg + births;
    
    window.setTimeout("countBirths()",1000);  // update each second
    }
    
    function addCommas(nStr) {
    nStr = nStr.replace(/[^0-9\.]/g,"");
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(nStr)) {
    nStr = nStr.replace(rgx, '$1,$2');
    }
    return nStr;
    }
    
    countBirths();
    </script>

    Of course, the world population is not increasing at this rate!


    "Money does not bring happiness, but it does enable you to be miserable in comfort". - Philip M's personal mantra

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect - thanks for your help.
    I realise that the population is not increasing at this rate, but the brief from my clients only includes births, not deaths!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •