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
Consume an async generator
easy10 minUse for await to collect values from an async generator.
- 2
Transform each awaited value
easy10 minUppercase each item as it is awaited and yielded.
- 3
Catch an error mid-stream
easy10 minCatch a rejection that happens partway through an async generator.
- 4
Mix plain and awaited yields
easy10 minYield some values immediately and one through a promise.
- 5
Use for await on a plain generator
medium10 minShow that for await also works on a synchronous generator.
Find the bug(5)
- 1
Fix for of used on an async generator
easy8 minAn async generator needs for await, not a plain for of.
- 2
Fix the missing async on the generator
easy8 minawait is only a keyword inside an async function, so using it in a plain generator will not even parse.
- 3
Fix the rejection never caught
easy8 minWithout a try block, the loop's error escapes unhandled.
- 4
Fix for await used outside an async function
easy8 minfor await can only be used inside an async function.
- 5
Fix the values pushed before awaiting
easy8 minThe 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