I have the following code:
var m = 0;
function addmoney(){
var today = new Date();
var s =today.getSeconds();
if(s == 30){
m += 10;
}
document.getElementById('mon').innerHTML=s+" money: "+m;
t=setTimeout(function(){addmoney()},500);
}
Basically what I'm doing is to add 10 to the value of m every 30 seconds. The problem here is that the variable was actually being added twice. I was wondering why this was the case?
EDIT: Sorry did not mean to do s++, eitherways it did not change much.
setTimeout(function(){addmoney()},500)is simpler written assetTimeout(addmoney,500)addmoney()for the first time?