Reap7z
Reap7z

Reputation: 21

Execute function alternately

How can I alternately perform 2 different functions

Example: Function 1 executed After 20 seconds function 2 executed and then everything starts again

Upvotes: 0

Views: 72

Answers (1)

Felipe Zavan
Felipe Zavan

Reputation: 1813

function function1() {
  // Do what you have to do...
  console.log("Function 1 called");
  setTimeout(function2, 20000);
}

function function2() {
  // Do what you have to do...
  console.log("Function 2 called");
  setTimeout(function1, 20000);
}

function1();

Upvotes: 1

Related Questions