0
0
Goprogramming~15 mins

Adding and updating values in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding and updating values
📖 Scenario: You are managing a small store's inventory. You want to keep track of how many items you have for each product.
🎯 Goal: Create a Go program that stores product quantities in a map, adds a new product, updates the quantity of an existing product, and then shows the final inventory.
📋 What You'll Learn
Create a map called inventory with initial products and quantities
Add a new product with a quantity to the inventory map
Update the quantity of an existing product in the inventory map
Print the final inventory map
💡 Why This Matters
🌍 Real World
Stores and businesses often track their inventory using maps or dictionaries to know how many items they have.
💼 Career
Understanding how to add and update values in maps is essential for managing data in many programming jobs, especially in backend development and data processing.
Progress0 / 4 steps
1
Create the initial inventory map
Create a map called inventory with these exact entries: "apple": 10, "banana": 5, and "orange": 8.
Go
Hint

Use map[string]int to create a map with string keys and int values.

2
Add a new product to the inventory
Add a new product "grape" with quantity 12 to the inventory map.
Go
Hint

Use inventory["grape"] = 12 to add a new key and value to the map.

3
Update the quantity of an existing product
Update the quantity of "banana" in the inventory map to 7.
Go
Hint

Assign the new quantity to inventory["banana"].

4
Print the final inventory
Print the inventory map to show all products and their quantities.
Go
Hint

Use fmt.Println(inventory) to print the map.