Human population counter
I’ve found a simple and cool JavaScript counter that is able to count current human population and it’s increase every second.
It:
- takes current date and time,
- calculates its different toward July 1, 1995 at 00:00:00 (when human population was 5 733 687 096)
- multiply known “human population increase” factor by the number of seconds that passed since then till now
In this particular (very old — year 1995) example result is printed into form’s text box. With a simple modifications you can have this turned into a actual JavaScript function to return result.
The JavaScript code is:
function popClock()
{
var t1 = new Date(95, 7, 1, 0, 0, 0);
var t2 = new Date();
var exp = (t2 - t1) / 365 / 24 / 3600 / 1000;
var p = Math.floor(5733687096 * Math.pow(1.01202, exp)) + "";
var pc = "";
var len = p.length;
for(i = len - 1; i >= 0; i--)
{
pc += p.charAt(len - 1 - i);
if(i&&!(i%3)) pc += ",";
}
document.popClock.pop.value = pc;
}
setInterval("popClock()", 100);
If you want to get rid of fancy number formatting (adding comma to separate thousands, millions and billion) then you can simplify the above code to:
function popClock()
{
var t1 = new Date(95, 7, 1, 0, 0, 0);
var t2 = new Date();
var exp = (t2 - t1) / 365 / 24 / 3600 / 1000;
var p = Math.floor(5733687096 * Math.pow(1.01202, exp)) + "";
document.popClock.pop.value = p;
}
setInterval("popClock()", 100);
Add some HTML form code:
<html>
<head></head>
<body>
<form name=popClock>
Human Population: <input size=14 name=pop>
</form>
</body>
</html>
And put one thing (JavaScript code) into another one (HTML). And… that’s it.
Here’s the entire code, both JavaScript and HTML:
<html>
<head>
<meta http-equiv="generator" content="tigerii minipad (c)2001">
</head>
<body>
<form name=popClock>
Human Population:
<input size=14 name=pop>
</form>
<script language=javascript>
function popClock()
{
var t1 = new Date(95, 7, 1, 0, 0, 0);
var t2 = new Date();
var exp = (t2 - t1) / 365 / 24 / 3600 / 1000;
var p = Math.floor(5733687096 * Math.pow(1.01202, exp)) + "";
document.popClock.pop.value = p;
}
setInterval("popClock()", 100);
</script>
</body>
</html>
That’s all folks! :>