Make a promise that resolves with a name and report it.
Acceptance criteria
- 1.#out should show got Ada.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Promises 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: “A promise is an object representing a value that is not ready yet.” .
1.Create and resolve a promiseexercise · easy · 10 min
Make a promise that resolves with a name and report it.
Passes when: #out should show got Ada.
2.Reject a promiseexercise · easy · 10 min · practice plan
Reject a promise and report the reason with catch.
Passes when: #out should show failed: no network.
3.Use Promise.resolveexercise · easy · 10 min · practice plan
Use a ready-made resolved promise and report its value.
Passes when: #out should show here.
4.Show it settles onceexercise · easy · 10 min · practice plan
Resolve twice and show only the first value is kept.
Passes when: #out should show first.
5.Show then runs laterexercise · medium · 10 min · practice plan
Report the order of a synchronous line and a then handler.
Passes when: #out should show sync then promise.
6.Fix the promise never resolvedbug fix · easy · 8 min
Nothing calls resolve, so the handler never runs.
Passes when: #out should show got Ada.
7.Fix then used for a rejectionbug fix · easy · 8 min · practice plan
A rejected promise is handled by catch, not by then.
Passes when: #out should show failed: no network.
8.Fix the value read outside the handlerbug fix · easy · 8 min · practice plan
The value only exists inside then.
Passes when: #out should show ready.
9.Fix reject used where resolve belongsbug fix · easy · 8 min · practice plan
The work succeeded, so the promise should resolve.
Passes when: #out should show worked.
10.Fix then called on the valuebug fix · easy · 8 min · practice plan
then belongs to the promise, not to what it resolves with.
Passes when: #out should show here.
Between them these tasks cover Promise, resolve and reject and then.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.