Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a goroutine that prints "Hello".
Go
go [1]() Drag options to blanks, or click blank then click option'
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.
✗ Incorrect
The correct way is to start an anonymous function as a goroutine that calls println("Hello").
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the receive operator incorrectly.
Confusing channel types with operators.
✗ Incorrect
To send a value into a channel, use the syntax: channel <- value.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel type syntax instead of the receive operator.
Confusing send and receive operators.
✗ Incorrect
To receive a value from a channel in a select case, use val <- ch.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of int for the channel type.
Using an incorrect buffer size.
✗ Incorrect
The channel should be of type int and have a buffer size of 3.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Using fmt.Print instead of fmt.Println.
✗ Incorrect
Use 'val' as the loop variable, 'ch' as the channel, and 'Println' to print the value.