Write a loader that hands its result to a callback.
Acceptance criteria
- 1.#out should show got Ada.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Async Callbacks 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: “An asynchronous callback is a function that runs once slow work has finished.” .
1.Pass a callback inexercise · easy · 10 min
Write a loader that hands its result to a callback.
Passes when: #out should show got Ada.
2.Use the error-first patternexercise · easy · 10 min · practice plan
Call back with null for the error and a name for the value.
Passes when: #out should show loaded Grace.
3.Report a failureexercise · easy · 10 min · practice plan
Call back with an error and report it.
Passes when: #out should show error: not found.
4.Nest two stepsexercise · easy · 10 min · practice plan
Run one callback inside another and report both results.
Passes when: #out should show one two.
5.Use a named handlerexercise · medium · 10 min · practice plan
Pass a named function as the callback rather than an inline one.
Passes when: #out should show done Alan.
6.Fix the result returned instead of passedbug fix · easy · 8 min
Returning from inside a timer gives the caller nothing.
Passes when: #out should show got Ada.
7.Fix the arguments in the wrong orderbug fix · easy · 8 min · practice plan
The error comes first and the value second.
Passes when: #out should show loaded Grace.
8.Fix the error never checkedbug fix · easy · 8 min · practice plan
The failure is being reported as a success.
Passes when: #out should show error: not found.
9.Fix the callback called with bracketsbug fix · easy · 8 min · practice plan
Passing callback() hands over its result, not the function.
Passes when: #out should show got Ada.
10.Fix the result used outside the callbackbug fix · easy · 8 min · practice plan
The second half is added before the callback has supplied the first.
Passes when: #out should show one two.
Between them these tasks cover Callbacks, Error-first pattern and Nesting.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.