0
0
Goprogramming~10 mins

Map creation in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a map from string to int.

Go
var ages [1]
Drag options to blanks, or click blank then click option'
A[]int
Bmap[string]int
Cstruct{}
Dchan int
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice syntax []int instead of map syntax.
Confusing map with channel or struct types.
2fill in blank
medium

Complete the code to initialize an empty map of string to int.

Go
ages := [1]
Drag options to blanks, or click blank then click option'
Amake(map[string]int)
Bnew(map[string]int)
Cmake([]int, 0)
D[]string{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using make with slice type instead of map type.
Using new which returns a pointer, not a map.
3fill in blank
hard

Fix the error in the map initialization code.

Go
var ages = [1]
Drag options to blanks, or click blank then click option'
Amap[string]int
Bmap[string]int()
Cmap[string]int{}
Dmap[string]int[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for map literals.
Using square brackets which are for slices or arrays.
4fill in blank
hard

Fill 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'
Amap[string]int
B85
C80
D[]int
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice type instead of map type.
Using a string instead of an integer for the value.
5fill in blank
hard

Fill 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'
Amap[string]int
B"eraser"
C3
D[]string
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.