Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<-' on the wrong side of the channel.
Confusing channel types with send/receive operators.
✗ Incorrect
To send a value into a channel in Go, use the syntax 'channel <- value'.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'chan' keyword instead of receive operator.
Using send operator '<-' on the wrong side.
✗ Incorrect
To receive a value from a channel, use '<-channel'.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the channel name as a string.
Using 'chan' keyword instead of the channel variable.
✗ Incorrect
To send a value into a channel, use the channel variable name followed by '<- value'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Creating a channel of wrong type.
Using wrong variable name to send the value.
✗ Incorrect
Use 'make(chan int)' to create an integer channel and 'ch <- 42' to send the value.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong channel type.
Mixing up send and receive operators.
Using wrong variable name for the channel.
✗ Incorrect
Create a string channel with 'chan string', receive with '<- ch', then print the value.