Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable of type int with value 10.
Go
var number [1] = 10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using string instead of int for a number.
Using float64 when an integer is needed.
โ Incorrect
The keyword int declares an integer variable in Go.
2fill in blank
mediumComplete the code to declare a variable of type bool with value true.
Go
var isActive [1] = true Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using int or string instead of bool for true/false values.
โ Incorrect
The type bool is used for true or false values in Go.
3fill in blank
hardFix the error in the code by choosing the correct type for the variable.
Go
var price [1] = 19.99
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using int for decimal numbers causes errors.
Using bool or string for numeric values.
โ Incorrect
The value 19.99 is a decimal number, so the variable must be float64.
4fill in blank
hardFill both blanks to create a map from string keys to int values.
Go
var scores map[[1]][2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Swapping key and value types.
Using float64 or bool for keys or values incorrectly.
โ Incorrect
Maps in Go use map[keyType]valueType. Here, keys are strings and values are integers.
5fill in blank
hardFill all three blanks to declare and initialize a slice of strings with three names.
Go
var names = [][1]{"[2]", "[3]", "Alice"}
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.
Mixing up the order of names.
โ Incorrect
The slice holds strings, so the type is string. The names are "John", "Bob", and "Alice".