Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, World!" in Go.
Go
package main import "fmt" func main() { fmt.[1]("Hello, World!") }
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 new line.
Using a non-existent function like Printfln.
✗ Incorrect
The 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.
Using float64 when an integer is intended.
✗ Incorrect
The variable count is declared as an integer using int type.
3fill in blank
hardFix the error in the code to correctly create a slice of strings named "fruits".
Go
package main
func main() {
fruits := [1]{"apple", "banana", "cherry"}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' or 'slice' as a type name, which are not valid Go types.
Using 'map' which is a key-value structure.
✗ Incorrect
In Go, a slice of strings is declared as []string.
4fill in blank
hardFill both blanks to create a map from string to int and add a key-value pair.
Go
package main
func main() {
ages := make(map[string][1])
ages["Alice"] = [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as the map value type but assigning an integer.
Assigning a string value instead of an integer.
✗ Incorrect
The map stores integers as values, so the type is int. The value assigned to "Alice" is 25.
5fill in blank
hardFill all three blanks to define a function that returns the sum of two integers.
Go
package main func [1](a [2], 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 value.
Using a function name that does not match the operation.
✗ Incorrect
The function is named add, takes two integers, and returns an integer.