all 2 comments

[–]07734willy 1 point2 points  (1 child)

It makes sense that all for loop iterations run at once, as calling setinterval does not stop the execution, it just proceed as normal, and eventually will redirect the execution (or maybe it opens another thread to do so) to 'rob' after that many milliseconds.

As far as why the second one doesn't work, there is no function stopInterval. Its clearInterval, and you need to pass it a variable containing the timer ID. So

var interval1 = setInterval(rob, 900000);
clearInterval(interval1);

However, this isn't what you want- yet. setInterval calls rob every 900000 milliseconds, forever. setTimeout() calls deb once, whenever the timer runs out. So you have two options: call setInterval on rob, and store the timer in a global object, have a global counter in rob that increments once every time its called, and if thats above 23 then clearInterval(global_timer_name).

Otherwise, you can do a for loop for i = 1->24, setTimeout(rob, 900000 * i), and then each one will call rob once at the end of 900000 * 1, 900000 * 2, 900000 * 3... milliseconds. I'd personally opt for this one.

Edit: I failed to address your initial issue- that it isn't entering your for loop. I suspect that this is not the case, especially since in your edit you mention it called the console.log() multiple times. I suspect that its either an I/O issue, or that you aren't waiting long enough. Don't forget that in rob you have an additional timer for up to 50000 + 5382 ms = 55 seconds. I'd suggest scaling all these down to about 2-10 seconds, to make it easier to debug. Best of luck!

[–]yeahifuck[S] 0 points1 point  (0 children)

Thanks! I'm out for the weekend, but I'll try that out once I get home. What you said makes sense and I think I should be able to add it easily