Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, Go!" to the console.
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.
Using Printfln is not a valid function.
โ Incorrect
The fmt.Println function prints the text followed by a new line.
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 type for a number value.
Using float64 when an integer is enough.
โ Incorrect
The variable count is declared as an integer using int.
3fill in blank
hardFix the error in the code to correctly compile and run.
Go
package main [1] "fmt" func main() { fmt.Println("Go is fun!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using package instead of import.
Trying to declare fmt as a variable.
โ Incorrect
The import keyword is used to include packages in Go.
4fill in blank
hardFill both blanks to create a map from string to int with two entries.
Go
package main
func main() {
scores := map[string][1]{
"Alice": [2],
"Bob": 90,
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using string as value type instead of int.
Using a string value for Alice's score.
โ Incorrect
The map keys are strings and values are integers. Alice's score is 85.
5fill in blank
hardFill all three blanks to define a function that returns the sum of two integers.
Go
package main func [1](a, b [2]) [3] { return a + b }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using different types for parameters and return.
Using a function name that does not match the action.
โ Incorrect
The function named add takes two integers and returns an integer sum.