Answers for "wait javascirpt"

4

how to wait in js

function wait(sec) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < sec*1000);
}

console.log('waiting')

wait(1)

console.log('i am done')
Posted by: Guest on February-02-2022
6

how to wait in javascript

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
Posted by: Guest on September-29-2020
0

js wait

function wait(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

function your_code() {
  //code stuff
  wait(1000); //waits 1 second before continuing
  //other code stuff
}
Posted by: Guest on October-22-2021
1

wait function in javascript

console.log("Hello");
setTimeout(() => {  console.log("World!"); }, 2000);
Posted by: Guest on October-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language