Complete the code to add a new key-value pair to the map.
package main import "fmt" func main() { ages := map[string]int{"Alice": 30} ages["Bob"] = [1] fmt.Println(ages) }
The value for the map key must be an integer. Here, 25 is the correct integer to add.
Complete the code to update the value for the key "Alice" in the map.
package main import "fmt" func main() { ages := map[string]int{"Alice": 30, "Bob": 25} ages["Alice"] = [1] fmt.Println(ages) }
To update the value for "Alice", assign a new integer value like 35.
Fix the error in the code by completing the blank to add a new key-value pair.
package main import "fmt" func main() { ages := map[string]int{"Alice": 30} ages[[1]] = 40 fmt.Println(ages) }
Map keys of type string must be enclosed in quotes when used as literals. "Bob" is correct.
Fill both blanks to add a new key-value pair and update an existing one.
package main import "fmt" func main() { ages := map[string]int{"Alice": 30, "Bob": 25} ages[[1]] = 40 ages[[2]] = 35 fmt.Println(ages) }
"Charlie" is a new key to add, and "Bob" is an existing key to update.
Fill all three blanks to add a new key-value pair, update an existing one, and print a value from the updated map.
package main import "fmt" func main() { ages := map[string]int{"Alice": 30, "Bob": 25} ages[[1]] = 40 ages[[2]] = 35 fmt.Println(ages[[3]]) }
"Charlie" is added with 40, "Alice" is updated to 35, and the value for "Bob" is printed.