JavaScript Generator Communication — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Generator Communication 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
Send a value in
easy10 minSend a name into a paused generator.
- 2
Show the first next only starts it
easy10 minConfirm the value passed to the first call is ignored.
- 3
Build a running total
easy10 minAdd several values into a generator one at a time.
- 4
Stop a generator early
easy10 minCall return on a generator and check it reports done.
- 5
Throw into a generator
medium10 minThrow an error into a generator that catches it.
Find the bug(5)
- 1
Fix the value expected on the first call
easy8 minNothing is paused yet when the first next() runs, so its argument is thrown away.
- 2
Fix the total never sent in
easy8 minCalling next with no argument never advances the running total.
- 3
Fix the generator used after return
easy8 minOnce returned, further calls should stay done.
- 4
Fix the throw with no catch inside
easy8 minWithout a try block inside, the thrown error escapes the generator entirely instead of being handled.
- 5
Fix while true assumed to hang
easy8 minA while true loop inside a generator is safe, since yield pauses it — capping it out of caution breaks the sequence early.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace