0
0
Node.jsframework~10 mins

Why timing matters in Node.js in Node.js - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message after 1 second using setTimeout.

Node.js
setTimeout(() => { console.log([1]); }, 1000);
Drag options to blanks, or click blank then click option'
A"Hello after 1 second"
BHello after 1 second
Cconsole.log('Hello')
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Passing a number instead of a string
Trying to call console.log inside the argument
2fill in blank
medium

Complete the code to run a function repeatedly every 2 seconds using setInterval.

Node.js
setInterval([1], 2000);
Drag options to blanks, or click blank then click option'
Aconsole.log
Bconsole.log('Repeat')
C() => console.log('Repeat')
D'Repeat'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a function
Calling console.log immediately instead of passing a function
Passing console.log without calling it
3fill in blank
hard

Fix the error in the code to correctly delay the execution of greet function by 3 seconds.

Node.js
function greet() { console.log('Hi!'); } setTimeout([1], 3000);
Drag options to blanks, or click blank then click option'
Agreet()
Bgreet
C() => greet()
DsetTimeout(greet, 3000)
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function immediately with parentheses
Passing a string instead of a function
Using setTimeout inside setTimeout
4fill in blank
hard

Fill both blanks to create a timer that stops after 5 seconds.

Node.js
const timer = setInterval(() => { console.log('Tick'); }, [1]); setTimeout(() => { clearInterval([2]); console.log('Stopped'); }, 5000);
Drag options to blanks, or click blank then click option'
A1000
Btimer
C500
DsetInterval
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong interval time
Passing wrong variable to clearInterval
Confusing setInterval with clearInterval
5fill in blank
hard

Fill all three blanks to create a promise that resolves after 2 seconds with message 'Done'.

Node.js
const myPromise = new Promise(([1], [2]) => { setTimeout(() => { [3]('Done'); }, 2000); });
Drag options to blanks, or click blank then click option'
Aresolve
Breject
Cconsole.log
Dcallback
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log instead of resolve
Swapping resolve and reject
Not calling resolve inside setTimeout