make a function wait code example
Example 1: wait javascript
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Example 2: javascript sleep function
sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
// V Must add this async keyword
sayHi = async () => {
// V Must include await
await sleep(1000); // Sleep 1000 milliseconds (1 second)
console.log('Hi');
// Rest of code...
}