Use Promise.all and report both values joined by a comma.
Acceptance criteria
- 1.#out should show 1,2.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Promise.all 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: “Promise.all waits for several promises at once instead of one after another.” .
1.Wait for two promisesexercise · easy · 10 min
Use Promise.all and report both values joined by a comma.
Passes when: #out should show 1,2.
2.Keep the input orderexercise · easy · 10 min · practice plan
Show that results follow the input order, not the finishing order.
Passes when: #out should show slow,fast.
3.Handle one failureexercise · easy · 10 min · practice plan
Catch the rejection that Promise.all passes on.
Passes when: #out should show caught: failed.
4.Report every outcomeexercise · easy · 10 min · practice plan
Use allSettled and report the two statuses joined by a comma.
Passes when: #out should show fulfilled,rejected.
5.Take the first to finishexercise · medium · 10 min · practice plan
Use Promise.race and report the quicker value.
Passes when: #out should show quick.
6.Fix the promises awaited one at a timebug fix · easy · 8 min
Independent work should run together with Promise.all.
Passes when: #out should show one two.
7.Fix the array not passedbug fix · easy · 8 min · practice plan
Promise.all takes one array, not separate arguments.
Passes when: #out should show 1,2.
8.Fix all used where allSettled is neededbug fix · easy · 8 min · practice plan
One rejection loses every result, but each outcome is wanted.
Passes when: #out should show fulfilled,rejected.
9.Fix the results sorted by finishing timebug fix · easy · 8 min · practice plan
Promise.all already returns them in input order.
Passes when: #out should show slow,fast.
10.Fix race used where all is neededbug fix · easy · 8 min · practice plan
Every value is wanted, not just the first to arrive.
Passes when: #out should show 1,2.
Between them these tasks cover Promise.all, allSettled and race.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.