0
0
Node.jsframework~10 mins

setTimeout and clearTimeout in Node.js - Interactive Code Practice

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

Complete the code to schedule a function to run after 2 seconds.

Node.js
setTimeout(() => { console.log('Hello!'); }, [1]);
Drag options to blanks, or click blank then click option'
A2000
B2
C0.002
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 2000 for 2 seconds delay.
Using 0.002 which is 2 microseconds, too short.
2fill in blank
medium

Complete the code to cancel a scheduled timeout using its ID.

Node.js
const timerId = setTimeout(() => { console.log('Run later'); }, 3000);
clearTimeout([1]);
Drag options to blanks, or click blank then click option'
AsetTimeout
B3000
Cnull
DtimerId
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the delay time (3000) instead of the timer ID.
Passing null or the function name.
3fill in blank
hard

Fix the error in the code to properly cancel the timeout.

Node.js
let id = setTimeout(() => console.log('Oops'), 5000);
clearTimeout([1]);
Drag options to blanks, or click blank then click option'
AtimeoutId
B5000
Cid
DsetTimeout
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name like timeoutId.
Passing the delay time (5000) instead of the ID.
4fill in blank
hard

Fill both blanks to schedule a message and then cancel it before it runs.

Node.js
const [1] = setTimeout(() => console.log('Bye!'), 4000);
[2]([1]);
Drag options to blanks, or click blank then click option'
Atimer
BclearTimeout
CsetTimeout
Dtimeout
Attempts:
3 left
💡 Hint
Common Mistakes
Using setTimeout instead of clearTimeout to cancel.
Not storing the timer ID in a variable.
5fill in blank
hard

Fill all three blanks to create a timeout, cancel it, and then schedule a new one.

Node.js
const [1] = setTimeout(() => console.log('First'), 3000);
[2]([1]);
const [3] = setTimeout(() => console.log('Second'), 3000);
Drag options to blanks, or click blank then click option'
AfirstTimer
BclearTimeout
CsecondTimer
DsetTimeout
Attempts:
3 left
💡 Hint
Common Mistakes
Not cancelling the first timer before creating the second.
Using the same variable name for both timers.