View Full Version : Need help to modify a formula for calculating in Javascript ?

09-03-2008, 08:00 PM

I would like to reproduce the counter present at the top of:
I've updated the javascript by adding cookies (copy below).

But this counter calculates the tons of greenhouse gases were emitted.
My counter has to calculate the number of bottles and cans which have not been recycled.

Do you know how to change the formula for calculating to obtain an integer value (without comma) which equals 14 bottles per second?

My javascript (with cookies) is:

<script language="JavaScript" type="text/javascript">
var sTotal = 0;
if (lire_cookie('compteur'))
sTotal = parseFloat(lire_cookie('compteur'));

function gazCount(start){
document.getElementById("counter").innerHTML = r2(sTotal*2.91);
document.cookie="compteur=" + sTotal;
setTimeout("gazCount();", 100);
function r2(n){
ans = n * 1000
ans = Math.round(ans /10) + ""
while (ans.length < 3) {ans = "0" + ans}
len = ans.length
ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
return ans
function lire_cookie(nom) {
var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen){
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return arguments_cookies(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;
return false;
function arguments_cookies(offset){
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));

window.onload = gazCount;

Thanks a lot,