Jump to content

Need help to modify a formula for calculating in Javascript ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
chrbar

chrbar

    Newbie

  • Members
  • Pip
  • 1 posts
Hello,

I would like to reproduce the counter present at the top of ensembleverslavenir.ca
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){
sTotal=sTotal+(0.1);
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;
</script>
Thanks a lot,
Chris

Edited by WingedPanther, 08 September 2008 - 08:29 AM.
add code tags


#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Use CODE tags.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums