christiang
05-24-2009, 07:25 AM
Hi, I am trying to make this script work as a population counter but I don't know how to use Java. Can you please help me with any suggestions on how to make it work? I have already been trying for three days..
Thank you,
Christian
<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>
Thank you,
Christian
<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>