Challenge - 5 Problems
Go Custom Package Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple custom package usage
What is the output of this Go program that uses a custom package named
greet?Go
package main import ( "fmt" "example.com/mypkg/greet" ) func main() { message := greet.Hello("Alice") fmt.Println(message) } // Package greet in example.com/mypkg/greet/greet.go package greet func Hello(name string) string { return "Hello, " + name + "!" }
Attempts:
2 left
💡 Hint
Check how the Hello function formats the string and if it includes punctuation.
✗ Incorrect
The Hello function returns the string "Hello, " concatenated with the name and an exclamation mark. So the output is exactly "Hello, Alice!".
🧠 Conceptual
intermediate1:30remaining
Understanding package visibility rules
In Go, which of the following statements about identifiers in custom packages is true?
Attempts:
2 left
💡 Hint
Think about how Go controls what is visible outside a package.
✗ Incorrect
In Go, only identifiers (functions, variables, types) that start with an uppercase letter are exported and can be accessed from other packages.
🔧 Debug
advanced2:30remaining
Fix the import path error in custom package usage
Given this main.go file, what is the cause of the error when trying to build the program?
main.go:
package main
import (
"fmt"
"mypkg/greet"
)
func main() {
fmt.Println(greet.Hello("Bob"))
}
The error is: cannot find package "mypkg/greet"
Attempts:
2 left
💡 Hint
Check how Go modules and import paths work for custom packages.
✗ Incorrect
Go requires import paths to be full module paths or relative paths. "mypkg/greet" is not a valid import path unless it matches the module path. The import path should match the module name or be relative.
📝 Syntax
advanced1:30remaining
Identify the syntax error in custom package declaration
Which option shows the correct syntax for declaring a custom package named
mathutil in Go?Attempts:
2 left
💡 Hint
Remember how package declarations are written in Go.
✗ Incorrect
The package declaration must be a single line starting with the keyword 'package' followed by the package name without braces. Option A follows this syntax correctly.
🚀 Application
expert2:00remaining
Number of exported functions in a custom package
Consider a Go package named
tools with the following functions:
func ExportedOne() {}
func exportedTwo() {}
func ExportedThree() {}
func exportedFour() {}
How many functions are accessible (exported) when importing the tools package in another Go file?Attempts:
2 left
💡 Hint
Recall Go's rule for exported identifiers based on capitalization.
✗ Incorrect
Only functions starting with an uppercase letter are exported. Here, ExportedOne and ExportedThree are exported, so 2 functions are accessible.