Multiply a value in one step and report it in the next.
Acceptance criteria
- 1.#out should show 10.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Promise Chaining 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: “Returning a value from then passes it to the next then in the chain.” .
1.Chain two stepsexercise · easy · 10 min
Multiply a value in one step and report it in the next.
Passes when: #out should show 10.
2.Build a string across stepsexercise · easy · 10 min · practice plan
Add a letter in each step and report the result.
Passes when: #out should show abc.
3.Wait for another promiseexercise · easy · 10 min · practice plan
Return a promise from a step so the chain waits for it.
Passes when: #out should show one two.
4.Catch at the endexercise · easy · 10 min · practice plan
Throw in the middle of a chain and catch it at the end.
Passes when: #out should show caught: broke.
5.Recover and continueexercise · medium · 10 min · practice plan
Catch a rejection, return a value, and carry on down the chain.
Passes when: #out should show recovered.
6.Fix the missing returnbug fix · easy · 8 min
Without a return the next step receives undefined.
Passes when: #out should show 10.
7.Fix the nested thenbug fix · easy · 8 min · practice plan
Nesting rebuilds callback hell; the promise should be returned instead.
Passes when: #out should show one two.
8.Fix the catch placed too earlybug fix · easy · 8 min · practice plan
A catch before the failing step cannot catch it.
Passes when: #out should show caught: broke.
9.Fix the steps run separatelybug fix · easy · 8 min · practice plan
Calling then twice on the same promise does not chain them.
Passes when: #out should show abc.
10.Fix the value used after the chainbug fix · easy · 8 min · practice plan
The chain has not finished when the line below runs.
Passes when: #out should show done.
Between them these tasks cover Chaining, Returning values and Flattening.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.