0

I want to pause but still run other code at the same time. For example:

while (true) {
    unit++
    // wait 3 seconds
}
// do this at the same time
while (true) {
    something += 25
    // wait 5 seconds
}
Bryan Chen
  • 45,816
  • 18
  • 112
  • 143

1 Answers1

1

This will increase unit by 1 every three seconds and something by 25 every five seconds. The time units are in milliseconds so divide by 1000 to get the time in seconds and vice versa.

setInterval(function() { 
    unit++;
}, 3000);

setInterval(function() { 
    something += 25;
}, 5000);
Andrew Ngo
  • 752
  • 8
  • 16