0
0
Goprogramming~10 mins

Best practices 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 declare a package in Go.

Go
package [1]
Drag options to blanks, or click blank then click option'
Afunc
Bfmt
Cvar
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fmt' as a package name instead of 'main'.
Trying to declare a function or variable instead of a package.
2fill in blank
medium

Complete the code to import the fmt package.

Go
import [1]fmt"
Drag options to blanks, or click blank then click option'
A"
B'
C`
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes or backticks instead of double quotes.
Using a colon instead of quotes.
3fill in blank
hard

Fix the error in the function declaration by completing the code.

Go
func [1]() {
    fmt.Println("Hello, Go!")
}
Drag options to blanks, or click blank then click option'
Afunc
BMain
Cmain
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing 'Main' instead of 'main'.
Using 'func' or 'print' as function names.
4fill in blank
hard

Fill both blanks to create a map of string keys to int values with a condition.

Go
ages := map[string]int{
    "Alice": 30,
    "Bob": 25,
    "Carol": 27,
}

for name, age := range ages {
    if age [1] 26 {
        fmt.Println(name, "is older than", [2])
    }
}
Drag options to blanks, or click blank then click option'
A>
Bage
C<
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Printing the variable 'name' instead of 'age' for the age value.
5fill in blank
hard

Fill all three blanks to create a slice of strings and print each element.

Go
names := [][1]{"Anna", "Ben", "Cara"}

for [2], [3] := range names {
    fmt.Println(index, name)
}
Drag options to blanks, or click blank then click option'
Astring
Bindex
Cname
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'string' for the slice type.
Using incorrect variable names in the for loop.