JavaScript Promises — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Promises lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Create and resolve a promise
easy10 minMake a promise that resolves with a name and report it.
- 2
Reject a promise
easy10 minReject a promise and report the reason with catch.
- 3
Use Promise.resolve
easy10 minUse a ready-made resolved promise and report its value.
- 4
Show it settles once
easy10 minResolve twice and show only the first value is kept.
- 5
Show then runs later
medium10 minReport the order of a synchronous line and a then handler.
Find the bug(5)
- 1
Fix the promise never resolved
easy8 minNothing calls resolve, so the handler never runs.
- 2
Fix then used for a rejection
easy8 minA rejected promise is handled by catch, not by then.
- 3
Fix the value read outside the handler
easy8 minThe value only exists inside then.
- 4
Fix reject used where resolve belongs
easy8 minThe work succeeded, so the promise should resolve.
- 5
Fix then called on the value
easy8 minthen belongs to the promise, not to what it resolves with.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace