0
0
Goprogramming~10 mins

Why channels are used in Go - Test Your Understanding

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

Complete the code to create a channel of integers.

Go
ch := make([1])
Drag options to blanks, or click blank then click option'
Achan
Bint
Cchannel int
Dchan int
Attempts:
3 left
💡 Hint
Common Mistakes
Using just the data type without 'chan'.
Writing 'channel' instead of 'chan'.
2fill in blank
medium

Complete the code to send the value 5 into the channel.

Go
ch := make(chan int)
go func() {
    ch [1] 5
}()
Drag options to blanks, or click blank then click option'
A<-
B<-chan
D<-chan int
Attempts:
3 left
💡 Hint
Common Mistakes
Using the arrow in the wrong direction.
Using channel receive syntax instead of send.
3fill in blank
hard

Fix the error in receiving a value from the channel.

Go
ch := make(chan int)
go func() {
    ch <- 10
}()
value := [1] ch
Drag options to blanks, or click blank then click option'
A<-
Bch
Cch <-
D<-chan
Attempts:
3 left
💡 Hint
Common Mistakes
Using send syntax instead of receive.
Omitting the arrow operator.
4fill in blank
hard

Fill both blanks to create a channel and send a value.

Go
var [1] [2]
[1] = make(chan string)
go func() {
    [1] <- "hello"
}()
Drag options to blanks, or click blank then click option'
Amessages
Bchan string
Cmsg
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-channel type for the variable.
Using an invalid variable name.
5fill in blank
hard

Fill all three blanks to receive a value from the channel and print it.

Go
ch := make(chan int)
go func() {
    ch <- 42
}()
value := [1] ch
fmt.[2]("Received: %d\n", [3])
Drag options to blanks, or click blank then click option'
A<-
BPrintf
Cvalue
DPrintln
Attempts:
3 left
💡 Hint
Common Mistakes
Using send syntax instead of receive.
Using Println instead of Printf with format specifier.
Passing wrong variable to Printf.