Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a greeting in 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 will not add a new line.
โ Incorrect
The Println function prints the text with a new line at the end.
2fill in blank
mediumComplete the code to declare a variable with value 10.
Go
package main
func main() {
var x [1] = 10
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using string or bool types for numbers.
โ Incorrect
The int type is used for whole numbers like 10.
3fill in blank
hardFix the error in the function declaration.
Go
package main
func [1]() {
// code
}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 'function' or 'def' which are not Go keywords.
โ Incorrect
The function name must be main exactly for the program entry point.
4fill in blank
hardFill both blanks to create a map with string keys and int values.
Go
package main
func main() {
m := make(map[[1]][2])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Mixing up key and value types.
โ Incorrect
Maps use key and value types inside brackets. Here keys are strings and values are integers.
5fill in blank
hardFill all three blanks to declare a slice of strings and add an element.
Go
package main import "fmt" func main() { var s [][1] s = append(s, [2]) fmt.[3](s) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using int instead of string for the slice type.
โ Incorrect
A slice of strings is declared with []string. We append a string literal and print with Println.