0
0
Goprogramming~15 mins

Map creation in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Map creation
📖 Scenario: You are creating a simple program to store and look up the prices of fruits in a store.
🎯 Goal: Build a Go program that creates a map with fruit names as keys and their prices as values.
📋 What You'll Learn
Create a map called fruitPrices with exact entries
Add a variable called newFruit with the value "Mango"
Add a new entry to the map using newFruit as the key and 120 as the value
Print the entire fruitPrices map
💡 Why This Matters
🌍 Real World
Maps are used to store related data where you want to quickly find a value by a key, like looking up prices by product names.
💼 Career
Understanding maps is important for many programming jobs because they help organize and access data efficiently.
Progress0 / 4 steps
1
Create the initial map
Create a map called fruitPrices with these exact entries: "Apple": 100, "Banana": 30, "Cherry": 75
Go
Hint

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

2
Add a new fruit variable
Add a variable called newFruit and set it to the string "Mango"
Go
Hint

Use newFruit := "Mango" to create the variable.

3
Add the new fruit to the map
Add a new entry to the fruitPrices map using newFruit as the key and 120 as the value
Go
Hint

Use fruitPrices[newFruit] = 120 to add the new entry.

4
Print the map
Print the entire fruitPrices map using fmt.Println
Go
Hint

Use fmt.Println(fruitPrices) to display the map.