Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet.
Go
func [1]() { println("Hello, friend!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
main instead of greet.Forgetting to name the function.
✗ Incorrect
The function name must be greet to match the task.
2fill in blank
mediumComplete the code to call the greet function.
Go
func main() {
[1]()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist.
Forgetting the parentheses after the function name.
✗ Incorrect
To run the greeting, we call the function named greet.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces
{} right after the function name instead of parentheses.Omitting parentheses entirely.
✗ Incorrect
Functions in Go need parentheses after the name, even if no parameters are used.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
string as return type instead of int.Using subtraction
- instead of addition.✗ Incorrect
The function must declare it returns an int and use + to add.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
int as return type instead of bool.Using
!= instead of == for comparison.✗ Incorrect
The function returns a bool. Use % for remainder and == to compare to zero.