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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Population Counter Modification

    Hi, I downloaded a some a free JavaScript population counter which shows the realtime population of the world.
    I would like to modify this counter to show the Australian Population instead. I am having trouble as I haven't used JavaScript before and only have a basic understanding of it. Can anyone please help me? The counter I would like to make is for a research project. Please help me if you can, I've been stuck for a few days already.. I will be very appreciative of your help

    This is a link to the Australian Beaureau of Statistics where there is a current realtime population counter.http://www.abs.gov.au/ausstats/abs%4...3?OpenDocument

    Here is the JavaScript I downloaded and would like to modify:

    Code:
    <script type="text/javascript">
    
    /*
    * World Populution Counter - By JavaScript Kit (http://www.javascriptkit.com)
    * Based on code by Adam Brown
    * This notice MUST stay intact for use
    * Visit JavaScript Kit (http://www.javascriptkit.com) for this script and more
    */
    
    function maind(){
    	startdate = new Date()
    	now(startdate.getYear(),startdate.getMonth(),startdate.getDate(),startdate.getHours(),startdate.getMinutes(),startdate.getSeconds())
    }
    
    
    function ChangeValue(number,pv){
    	numberstring =""
    	var j=0 
    	var i=0
    	while (number > 1)
    	 { 
    
    	    numberstring = (Math.round(number-0.5) % 10) + numberstring
    	    number= number / 10
    	    j++
    	    if (number > 1 && j==3) { 
    			numberstring = "," + numberstring 
    			j=0}
    	    i++
    	 }
    
    	 numberstring=numberstring
    
    if (pv==1) {document.getElementById("worldpop").innerHTML=numberstring }
    }
    
    
    function now(year,month,date,hours,minutes,seconds){       
    startdatum = new Date(year,month,date,hours,minutes,seconds)
    
    var now = 5600000000.0
    var now2 = 5690000000.0
    var groeipercentage = (now2 - now) / now *100
    var groeiperseconde = (now * (groeipercentage/100))/365.0/24.0/60.0/60.0 
    nu = new Date ()                
    schuldstartdatum = new Date (96,1,1)                            
    secondenoppagina = (nu.getTime() - startdatum.getTime())/1000
    totaleschuld= (nu.getTime() - schuldstartdatum.getTime())/1000*groeiperseconde + now
    ChangeValue(totaleschuld,1);
    
    
    timerID = setTimeout("now(startdatum.getYear(),startdatum.getMonth(),startdatum.getDate(),startdatum.getHours(),startdatum.getMinutes(),startdatum.getSeconds())",200)
    }
    
    window.onload=maind
    </script>
    
    Current world population (estimated): <span id="worldpop" style="font-weight: bold"></span>.
    
    <p style="font: normal 11px Arial">This free script provided by<br />
    <a href="http://www.javascriptkit.com">JavaScript Kit</a></p>
    Last edited by christiang; 05-24-2009 at 12:31 PM. Reason: adding information

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try this:-


    Code:
    <div id = "AustPop"></div>
    
    <script type = "text/javascript">
    
    var basisDate = new Date(2009,4,24,05,46,36).getTime();   // 24 May 2009 at 05:46:36 (Canberra Time)
    var basisPop = 21769052;  // population as at that time
    
    function ozPop() {
    var now = new Date();
    var now = new Date().getTime();
    var diff = (now - basisDate)/60000;  // minutes
    var newPop = parseInt((diff/1.5) + basisPop);  // increase by 1 every 1.5 minutes
    newPop = newPop.toString();
    newPop = addCommas(newPop);  // format with commas
    msg = "The population of Australia as of this moment is estimated to be:-  ";
    document.getElementById("AustPop").innerHTML = msg + newPop;
    
    window.setTimeout("ozPop()",30000);  // update each half minute
    }
    
    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;
    }
    
    </script>
    He thought he saw a Kangaroo
    That worked a coffee-mill:
    He looked again, and found it was
    A Vegetable-Pill.
    "Were I to swallow this," he said,
    "I should be very ill!"
    - Lewis Carroll
    Last edited by Philip M; 05-23-2009 at 09:25 PM. Reason: Add quotation

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Philip, thanks for responding with the script. I've tested it and it's not working..? I'm trying to understand what it is I need to change but I don't Know enough about JavaScript. Do you know what it could be that needs to be adjusted in the Script you sent?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    As I said in the other thread you posted, it works fine for me.

    I have to say that it is somewhat irritating when people bleat that a script which has been written specially for them (without charge) by an experienced coder does not work. "The fault, dear Chistiang, lies not in the stars but in ourselves."


  •  

    Tags for this Thread

    Posting Permissions

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