Go Exercises

Fill in the blanks to test your knowledge.

1

Declare and initialize a variable with :=

name "Alice"
2

Print to stdout using fmt

fmt.("Hello, Go!")
3

Declare a function that returns an int

add(a, b int) int {
return a + b
}
4

Launch a goroutine

doWork()
5

Use defer to run a function at end of scope

file.Close()
6

Import the fmt package

"fmt"
7

Declare a slice of integers

nums := [] {1, 2, 3}
8

Use a for range loop over a slice

for i, v := nums {
fmt.Println(i, v)
}