Use a timer to build the order first, second, third.
Acceptance criteria
- 1.#out should show first second third.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Asynchronous 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: “Asynchronous JavaScript starts a slow job and carries on without waiting for it.” .
1.Report the running orderexercise · easy · 10 min
Use a timer to build the order first, second, third.
Passes when: #out should show first second third.
2.Show the result is not readyexercise · easy · 10 min · practice plan
Read a value before the timer sets it and report what you get.
Passes when: #out should show nothing yet.
3.Use the value where it arrivesexercise · easy · 10 min · practice plan
Report the value from inside the callback, once it exists.
Passes when: #out should show arrived.
4.Show a timer waits its turnexercise · easy · 10 min · practice plan
Even a delay of zero runs after the current code, so report both in order.
Passes when: #out should show now later.
5.Count synchronously firstexercise · medium · 10 min · practice plan
Finish a loop, then report from a timer that the loop went first.
Passes when: #out should show loop then timer.
6.Fix the value read too earlybug fix · easy · 8 min
The value is read before the timer has set it.
Passes when: #out should show arrived.
7.Fix the order assumed to be top to bottombug fix · easy · 8 min · practice plan
The timer callback runs after the code below it.
Passes when: #out should show now later.
8.Fix the result expected as a returnbug fix · easy · 8 min · practice plan
A function that schedules work cannot return its result.
Passes when: #out should show Ada.
9.Fix the missing reportbug fix · easy · 8 min · practice plan
The timer updates a variable but never shows it.
Passes when: #out should show done.
10.Fix the order built in the wrong placebug fix · easy · 8 min · practice plan
The join happens before the timer has added its entry.
Passes when: #out should show loop then timer.
Between them these tasks cover Async basics, Blocking and Ordering.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.