25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started โ†’

Interactive Go ยท Lesson

Quest: The War Party

The war party charges, each member striking at once. This final concurrency quest brings it all together: a goroutine per attacker, a channel to collect their damage, and a WaitGroup to know when every blow has landed before we tally up.

Your Quest

Inside the loop, launch a goroutine for each d that sends d into the results channel and then calls wg.Done(). Pass d in as an argument so each goroutine gets its own value.

The damages are 10, 20, and 30, so:

60

Hint

go func(d int) { results <- d; wg.Done() }(d) โ€” passing d as a parameter gives each goroutine its own copy.

Additional Scrolls of Wisdom