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 trialstr
3,149 PointsStuck on the Dictionary Code Challenge within the Collections and Control Flow lessons.
I'm currently stuck on the Dictionary code challenge, specifically when it asks you to retrieve the "apple pie" value from the dictionary using it's assigned key "AP" and then assign that to a constant of "applePie". To my understanding, in the lesson we were taught to retrieve items from the dictionary by "reading" them using the dictionary name followed by ["the key"] I.E. iceCream["AP"] . I also can't remember exactly how to assign that value to a new constant. If someone could refresh my memory and look over my code, I'd greatly appreciate it. Thank you for your time.
// Enter your code below
var iceCream = ["CC": "Chocolate Chip",
"AP": "Apple Pie",
"PB": "Peanut Butter"]
iceCream.updateValue ("Rocky Road", forKey: "RR")
iceCream["AP"]
let applePie = //iceCream ? How do I go about assigning the "Apple Pie" key to the constant "applePie"//
1 Answer
jcorum
71,830 PointsYou were close! Here you go:
var iceCream = ["CC": "Chocolate Chip",
"AP": "Apple Pie",
"PB": "Peanut Butter"]
iceCream.updateValue ("Rocky Road", forKey: "RR")
let applePie = iceCream["AP"]
Happy coding!