0
0
Goprogramming~10 mins

Why functions are needed in Go - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a function named greet.

Go
func [1]() {
    println("Hello, friend!")
}
Drag options to blanks, or click blank then click option'
Agreet
Bmain
Chello
DsayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using main instead of greet.
Forgetting to name the function.
2fill in blank
medium

Complete the code to call the greet function.

Go
func main() {
    [1]()
}
Drag options to blanks, or click blank then click option'
Aprint
Bhello
Cgreet
DsayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist.
Forgetting the parentheses after the function name.
3fill in blank
hard

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

Go
func greet[1] {
    println("Hello!")
}
Drag options to blanks, or click blank then click option'
A[]
B()
C<>
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} right after the function name instead of parentheses.
Omitting parentheses entirely.
4fill in blank
hard

Fill both blanks to create a function that adds two numbers and returns the result.

Go
func add(a int, b int) [1] {
    return a [2] b
}
Drag options to blanks, or click blank then click option'
Aint
B+
Cstring
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as return type instead of int.
Using subtraction - instead of addition.
5fill in blank
hard

Fill all three blanks to create a function that checks if a number is even.

Go
func isEven(n int) [1] {
    return n [2] 2 [3] 0
}
Drag options to blanks, or click blank then click option'
Abool
B%
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using int as return type instead of bool.
Using != instead of == for comparison.