0
0
Goprogramming~10 mins

Package scope rules 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 named main.

Go
package [1]
Drag options to blanks, or click blank then click option'
Amain
Bfmt
Cpackage
Dfunc
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fmt' as package name instead of 'main'.
Writing 'package' as the package name.
Using 'func' which is a keyword, not a package name.
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 quotes directly after import without parentheses.
Using curly braces or square brackets instead of parentheses.
3fill in blank
hard

Fix the error in the variable declaration to make it package scoped.

Go
var [1] = 42
Drag options to blanks, or click blank then click option'
AmyVar
Bmy_var
C_myVar
DMyVar
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase variable names which are not exported.
Using underscores which do not affect scope.
4fill in blank
hard

Fill both blanks to define a package-level function and call it inside main.

Go
func [1]() {
	println("Hello from package scope")
}

func main() {
	[2]()
}
Drag options to blanks, or click blank then click option'
AGreet
Bgreet
CPrint
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase function names which are not exported.
Calling a different function name than defined.
5fill in blank
hard

Fill all three blanks to create a package-level constant, a variable, and a function that uses them.

Go
const [1] = "GoLang"

var [2] = 2024

func [3]() string {
	return [1] + " " + string([2])
}
Drag options to blanks, or click blank then click option'
AVersion
Bversion
CGetVersion
DgetVersion
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names which are not exported.
Mismatching names between declaration and usage.