Reputation: 161
Hi i am little bit confused to write this loop. It should alert for every fifteen minutes stating with 0 mins.
var i = 0;
var l = 900;
var m = 90000;
for (i=i; i<=m; i++){
alert(i+l);
i=i+l;
}
Upvotes: 1
Views: 2080
Reputation: 76408
Using @janith's answer, I suspect your next question will be how do I stop an interval
:
var intId = setInterval(function()
{
alert('foo');
},15*60000);//assign to var
clearInterval(intId);//stops the interval
Or even better (and safer, without globals):
var intervalMgmt = (function(intId)
{
var start = function(cb,time)
{
intId = setInterval(cb,time);
};
var stop = function()
{
clearInterval(intId);
};
return {start:start,stop:stop};
})();
intervalMgmt.start(function()
{
console.log('foo');
},5000);//logs "foo" every 5 seconds
//some time later:
intervalMgmt.stop();//stops the interval
Upvotes: 2
Reputation: 23208
Use following code:
var i = 0;
var l = 900;
var m = 90000;
var setIntervalConst = setInterval(function(){
if(i > m){
clearInterval(setIntervalConst ); return;
}
alert(i+l);
i=i+l;
},15*60*1000);
Upvotes: 0
Reputation: 1025
What you need is the setInterval method:
setInterval(function(){
alert('hi');
},15*60*1000);
Upvotes: 7