Skip to main content

JavaScript async and await — exercises and bug fixes

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

    Await a promise

    easy10 min

    Await a resolved promise inside an async function and report the value.

  2. 2

    Await a timer

    easy10 min

    Await a promise that resolves from a timer.

  3. 3

    Await twice in a row

    easy10 min

    Await two steps in sequence and report the combined result.

  4. 4

    Await inside a loop

    easy10 min

    Total three awaited values in a loop.

  5. 5

    Show an async function returns a promise

    medium10 min

    Report whether calling an async function gives back a promise.

Find the bug(5)

  1. 1

    Fix the missing await

    easy8 min

    Without await you get the promise, not the value.

  2. 2

    Fix the missing async keyword

    easy8 min

    await only works inside an async function.

  3. 3

    Fix the value read after the call

    easy8 min

    The async function has not finished when the next line runs.

  4. 4

    Fix the total added before awaiting

    easy8 min

    The promise itself is being added instead of its value.

  5. 5

    Fix the async function never called

    easy8 min

    Defining an async function does not run it.

Ready to write the code?

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

Open the workspace