Use setTimeout to report done after a short delay.
Acceptance criteria
- 1.#out should show done.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript setTimeout chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “setTimeout runs a function once after a delay.” .
1.Run something laterexercise · easy · 10 min
Use setTimeout to report done after a short delay.
Passes when: #out should show done.
2.Cancel a timerexercise · easy · 10 min · practice plan
Schedule a timer, cancel it, and report cancelled instead.
Passes when: #out should show cancelled.
3.Pass an argumentexercise · easy · 10 min · practice plan
Pass a name through setTimeout and greet it.
Passes when: #out should show hello Ada.
4.Chain two timersexercise · easy · 10 min · practice plan
Schedule a second timer from inside the first and report both steps.
Passes when: #out should show one two.
5.Check the delay was respectedexercise · medium · 10 min · practice plan
Report that at least ten milliseconds passed.
Passes when: #out should show waited.
6.Fix the handler called immediatelybug fix · easy · 8 min
Brackets run the function now instead of scheduling it.
Passes when: #out should show later.
7.Fix the timer never cancelledbug fix · easy · 8 min · practice plan
The id is not kept, so clearTimeout has nothing to cancel.
Passes when: #out should show cancelled.
8.Fix clearInterval used on a timeoutbug fix · easy · 8 min · practice plan
A timeout is cancelled with clearTimeout.
Passes when: #out should show stopped.
9.Fix the argument never passedbug fix · easy · 8 min · practice plan
Extra arguments go after the delay, not before it.
Passes when: #out should show hello Grace.
10.Fix the second timer scheduled too earlybug fix · easy · 8 min · practice plan
Both timers were started at once, so the order is not guaranteed.
Passes when: #out should show one two.
Between them these tasks cover setTimeout, clearTimeout and Timer arguments.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.