Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a map from string to int.
Go
var ages [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice syntax []int instead of map syntax.
Confusing map with channel or struct types.
✗ Incorrect
The correct syntax to declare a map from string to int in Go is map[string]int.
2fill in blank
mediumComplete the code to initialize an empty map of string to int.
Go
ages := [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
make with slice type instead of map type.Using
new which returns a pointer, not a map.✗ Incorrect
To create an empty map in Go, use make(map[string]int).
3fill in blank
hardFix the error in the map initialization code.
Go
var ages = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for map literals.
Using square brackets which are for slices or arrays.
✗ Incorrect
To initialize a map with a literal, use map[string]int{}. Parentheses or brackets are incorrect here.
4fill in blank
hardFill both blanks to create a map with initial values.
Go
scores := [1]{ "Alice": [2], "Bob": 90, }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice type instead of map type.
Using a string instead of an integer for the value.
✗ Incorrect
The map type is map[string]int and the value for "Alice" is 85.
5fill in blank
hardFill all three blanks to create a map and add a new key-value pair.
Go
items := [1]{ "pen": 5, "notebook": 10, } items[[2]] = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice type instead of map type.
Forgetting quotes around string keys.
Assigning a string value instead of an integer.
✗ Incorrect
The map type is map[string]int. The new key is "eraser" and the value is 3.