Skip to main content

JavaScript Promise Chaining — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Promise Chaining 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

    Chain two steps

    easy10 min

    Multiply a value in one step and report it in the next.

  2. 2

    Build a string across steps

    easy10 min

    Add a letter in each step and report the result.

  3. 3

    Wait for another promise

    easy10 min

    Return a promise from a step so the chain waits for it.

  4. 4

    Catch at the end

    easy10 min

    Throw in the middle of a chain and catch it at the end.

  5. 5

    Recover and continue

    medium10 min

    Catch a rejection, return a value, and carry on down the chain.

Find the bug(5)

  1. 1

    Fix the missing return

    easy8 min

    Without a return the next step receives undefined.

  2. 2

    Fix the nested then

    easy8 min

    Nesting rebuilds callback hell; the promise should be returned instead.

  3. 3

    Fix the catch placed too early

    easy8 min

    A catch before the failing step cannot catch it.

  4. 4

    Fix the steps run separately

    easy8 min

    Calling then twice on the same promise does not chain them.

  5. 5

    Fix the value used after the chain

    easy8 min

    The chain has not finished when the line below runs.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace