Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, Go!".
Go
package main import "fmt" func main() { fmt.[1]("Hello, Go!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using Print instead of Println which does not add a newline.
โ Incorrect
The Println function prints the text with a newline at the end.
2fill in blank
mediumComplete the code to declare a variable named 'count' of type int with value 10.
Go
package main
func main() {
var count [1] = 10
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using string or float64 which are not integer types.
โ Incorrect
The variable count should be of type int to hold integer values.
3fill in blank
hardFix the error in the function signature to accept an integer parameter named 'n'.
Go
package main
func printNumber([1]) {
// function body
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
int n which is incorrect in Go.โ Incorrect
In Go, function parameters are declared as name type, so n int is correct.
4fill in blank
hardFill both blanks to create a map from string to int with one key-value pair.
Go
package main
func main() {
m := map[[1]][2]{
"age": 30,
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using float64 or bool for keys or values which is incorrect here.
โ Incorrect
The map keys are strings and values are integers, so string and int are correct.
5fill in blank
hardFill all three blanks to create a slice of integers and append 5 to it.
Go
package main import "fmt" func main() { nums := [][1]{1, 2, 3} nums = append(nums, [2]) fmt.[3](nums) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using string instead of int for the slice type.
Forgetting to append the correct value.
โ Incorrect
The slice holds integers, so int is correct. We append the number 5, and print with Println.