Complete the code to print a message after 1 second using setTimeout.
setTimeout(() => { console.log([1]); }, 1000);The message to print must be a string inside quotes.
Complete the code to run a function repeatedly every 2 seconds using setInterval.
setInterval([1], 2000);
setInterval expects a function as the first argument, so we use an arrow function.
Fix the error in the code to correctly delay the execution of greet function by 3 seconds.
function greet() { console.log('Hi!'); } setTimeout([1], 3000);Passing the function name without parentheses delays execution correctly.
Fill both blanks to create a timer that stops after 5 seconds.
const timer = setInterval(() => { console.log('Tick'); }, [1]); setTimeout(() => { clearInterval([2]); console.log('Stopped'); }, 5000);Use 1000 ms for interval and clearInterval with the timer variable to stop it.
Fill all three blanks to create a promise that resolves after 2 seconds with message 'Done'.
const myPromise = new Promise(([1], [2]) => { setTimeout(() => { [3]('Done'); }, 2000); });
Promises use resolve and reject functions; resolve is called after timeout.