Skip to main content

JavaScript Async Iteration — exercises and bug fixes

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

    Consume an async generator

    easy10 min

    Use for await to collect values from an async generator.

  2. 2

    Transform each awaited value

    easy10 min

    Uppercase each item as it is awaited and yielded.

  3. 3

    Catch an error mid-stream

    easy10 min

    Catch a rejection that happens partway through an async generator.

  4. 4

    Mix plain and awaited yields

    easy10 min

    Yield some values immediately and one through a promise.

  5. 5

    Use for await on a plain generator

    medium10 min

    Show that for await also works on a synchronous generator.

Find the bug(5)

  1. 1

    Fix for of used on an async generator

    easy8 min

    An async generator needs for await, not a plain for of.

  2. 2

    Fix the missing async on the generator

    easy8 min

    await is only a keyword inside an async function, so using it in a plain generator will not even parse.

  3. 3

    Fix the rejection never caught

    easy8 min

    Without a try block, the loop's error escapes unhandled.

  4. 4

    Fix for await used outside an async function

    easy8 min

    for await can only be used inside an async function.

  5. 5

    Fix the values pushed before awaiting

    easy8 min

    The value should be pushed after it resolves, not the raw promise.

Ready to write the code?

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

Open the workspace