Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Population Counter script not working

christianghezzchristianghezz Posts: 1Member
Hi, I am having so much trouble tring to get a population counter script to work. I haven't used JavaScript before. This script was done by a friend but it doesn't work. Can you please have a look and suggest any changes to the script so it will work? I have already sspent three days on it and now I am desperate..

Thanks if you can help


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;

Sign In or Register to comment.