0
0
Goprogramming~10 mins

Sending and receiving values 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 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<-chan<-
B<-chan
C<-
D<-chan<-chan
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<-' on the wrong side of the channel.
Confusing channel types with send/receive operators.
2fill in blank
medium

Complete the code to receive a value from the channel and store it in variable x.

Go
ch := make(chan int)
go func() {
    ch <- 10
}()
x := [1] ch
Drag options to blanks, or click blank then click option'
Asend
Bmake
Cchan
D<-
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'chan' keyword instead of receive operator.
Using send operator '<-' on the wrong side.
3fill in blank
hard

Fix the error in the code to correctly send the string "hello" into the channel.

Go
ch := make(chan string)
go func() {
    [1] <- "hello"
}()
Drag options to blanks, or click blank then click option'
A"ch"
Bch
Cchan
Dmake
Attempts:
3 left
💡 Hint
Common Mistakes
Using the channel name as a string.
Using 'chan' keyword instead of the channel variable.
4fill in blank
hard

Fill both blanks to create a channel of integers and send the value 42 into it.

Go
ch := make([1])
go func() {
    [2] <- 42
}()
Drag options to blanks, or click blank then click option'
Achan int
Bchan string
Cch
Dchan bool
Attempts:
3 left
💡 Hint
Common Mistakes
Creating a channel of wrong type.
Using wrong variable name to send the value.
5fill in blank
hard

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

Go
ch := make([1])
go func() {
    ch <- "GoLang"
}()
value := [2] [3]
fmt.Println(value)
Drag options to blanks, or click blank then click option'
Achan string
B<-
Cch
Dchan int
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong channel type.
Mixing up send and receive operators.
Using wrong variable name for the channel.