Skip to main content

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. 1

    Create and resolve a promise

    easy10 min

    Make a promise that resolves with a name and report it.

  2. 2

    Reject a promise

    easy10 min

    Reject a promise and report the reason with catch.

  3. 3

    Use Promise.resolve

    easy10 min

    Use a ready-made resolved promise and report its value.

  4. 4

    Show it settles once

    easy10 min

    Resolve twice and show only the first value is kept.

  5. 5

    Show then runs later

    medium10 min

    Report the order of a synchronous line and a then handler.

Find the bug(5)

  1. 1

    Fix the promise never resolved

    easy8 min

    Nothing calls resolve, so the handler never runs.

  2. 2

    Fix then used for a rejection

    easy8 min

    A rejected promise is handled by catch, not by then.

  3. 3

    Fix the value read outside the handler

    easy8 min

    The value only exists inside then.

  4. 4

    Fix reject used where resolve belongs

    easy8 min

    The work succeeded, so the promise should resolve.

  5. 5

    Fix then called on the value

    easy8 min

    then 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