/    Sign up×
Community /Pin to ProfileBookmark

Need help to modify a formula for calculating in Javascript ?

Hello,

I would like to reproduce the counter present at the top of:
[url]http://www.ensembleverslavenir.ca/en/home.asp[/url]
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

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @chrbar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...