1//code before the pause
2setTimeout(function(){
3 //do what you need here
4}, 2000);
5
1function sleep(milliseconds) {
2 const date = Date.now();
3 let currentDate = null;
4 do {
5 currentDate = Date.now();
6 } while (currentDate - date < milliseconds);
7}
8
9console.log("Hello");
10sleep(2000);
11console.log("World!");
1//code before the pause
2setTimeout(function(){
3 //do what you need here
4}, 2000);
1function sleep(milliseconds) {
2 const start = Date.now();
3 while (Date.now() - start < milliseconds);
4}
5
6console.log("Hello");
7sleep(2000);
8console.log("World!");
9
1function wait(milliseconds) {
2 const date = Date.now();
3 let currentDate = null;
4 do {
5 currentDate = Date.now();
6 } while (currentDate - date < milliseconds);
7}
8
9function your_code() {
10 //code stuff
11 wait(1000); //waits 1 second before continuing
12 //other code stuff
13}