0
0
Goprogramming~10 mins

Common concurrency patterns in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a goroutine that prints "Hello".

Go
go [1]()
Drag options to blanks, or click blank then click option'
Afmt.Println("Hello")
Bprintln("Hello")
Cfunc() { fmt.Println("Hello") }
Dfunc() { println("Hello") }
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call a function directly without wrapping it in a function literal.
Using fmt.Println without importing fmt or without wrapping in a function.
2fill in blank
medium

Complete the code to send the integer 5 into the channel ch.

Go
ch [1] 5
Drag options to blanks, or click blank then click option'
A<-
B<-chan
C<-chan<-chan
D<-chan<-
Attempts:
3 left
💡 Hint
Common Mistakes
Using the receive operator incorrectly.
Confusing channel types with operators.
3fill in blank
hard

Fix the error in the select statement to receive from channel ch.

Go
select {
case val [1] ch:
    fmt.Println(val)
}
Drag options to blanks, or click blank then click option'
A<-chan<-
B<-chan
C<-
D<-chan<-chan
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel type syntax instead of the receive operator.
Confusing send and receive operators.
4fill in blank
hard

Fill both blanks to create a buffered channel of integers with capacity 3.

Go
ch := make(chan [1], [2])
Drag options to blanks, or click blank then click option'
Aint
Bstring
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of int for the channel type.
Using an incorrect buffer size.
5fill in blank
hard

Fill all three blanks to range over channel ch and print received values.

Go
for [1] := range [2] {
    fmt.[3](val)
}
Drag options to blanks, or click blank then click option'
Aval
Bch
CPrintln
DPrint
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Using fmt.Print instead of fmt.Println.