Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAry de Oliveira
28,298 PointsSwift 2.0
Challenge Task 2 of 4
An ice cream shop with only three flavors would be somewhat limited. Let's add another flavor to the list!
Add the value, "Rocky Road", for the key "RR" to the iceCream dictionary.
You can either add it using subscript syntax or the method updateValue(value: Value, forKey key: Key). The method takes a value and a key. Example: updateValue("Pistachio", forKey: "PI")
I am Stak ....
// Enter your code below
var iceCream = ["CC": "Chocolate Chip",
"AP": "Apple Pie",
"PB": "Peanut Butter"
"RR": "Rocky Road"]
updateValue (value: Value, forKey key: Key)
updateValue ("Pistachio", forKey: "PI")
4 Answers
Ian Rushton
15,789 PointsI did this a different way.
First make sure that your dictionary looks like this:
var iceCream = ["CC": "Chocolate Chip",
"AP": "Apple Pie",
"PB": "Peanut Butter"]
Then, using the subscript syntax I added the value for Rocky Road as follows:
iceCream["RR"] = "Rocky Road"
The other way to do this is:
iceCream.updateValue("Rocky Road", forKey: "RR")
Does this help? I notice that your code looks like you may be on a different stage, if this is the case let me know and I'll give it another try!
Michael Dussie
1,891 PointsAn ice cream shop with only three flavors would be somewhat limited. Let's add another flavor to the list!
Ary de Oliveira
28,298 Pointsyou good thank you
Kellington Chidza
866 PointsiceCream["RR"] = "Rocky Road"