0
0
Goprogramming~10 mins

Creating custom packages in Go - Interactive 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 named "mathutils".

Go
package [1]
Drag options to blanks, or click blank then click option'
Amathutils
Bmain
Cfmt
Dutils
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' instead of the custom package name.
Forgetting the package declaration line.
2fill in blank
medium

Complete the code to import the "fmt" package for printing.

Go
import [1]
Drag options to blanks, or click blank then click option'
A"mathutils"
B"os"
C"net/http"
D"fmt"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the package name.
Importing the wrong package for printing.
3fill in blank
hard

Fix the error in the function declaration to make it exported from the package.

Go
func [1](a int, b int) int {
    return a + b
}
Drag options to blanks, or click blank then click option'
Asum
Badd
CAdd
DsumNumbers
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase function names for exported functions.
Not capitalizing the first letter of the function name.
4fill in blank
hard

Fill both blanks to create a map of word lengths for words longer than 3 characters.

Go
lengths := map[string]int{
    [1]: [2],
}

for _, word := range []string{"go", "code", "fun", "package"} {
    if len(word) > 3 {
        lengths[word] = len(word)
    }
}
Drag options to blanks, or click blank then click option'
A"code"
B4
C"word"
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string keys.
Using the word itself as a key without quotes.
5fill in blank
hard

Fill all three blanks to create a function that returns a map of uppercase words and their lengths for words longer than 3 characters.

Go
func [1](words []string) map[string]int {
    result := make(map[string]int)
    for _, [2] := range words {
        if len([2]) > 3 {
            result[strings.ToUpper([2])] = len([2])
        }
    }
    return result
}
Drag options to blanks, or click blank then click option'
AWordLengths
Bword
Cw
Dwords
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not capitalizing the function name.