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 trialRyan Anderson
4,610 PointsDont understand challenge task 2 of 2
show me how to do it
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies
3 Answers
Ryan Jin
15,337 PointsLike an array, but instead you type in the key, not the index
let ukCurrency = currencies["UK"]
Matthew Wiese
1,659 PointsThe answer it is looking for is...
let ukCurrency = currencies["UK"]
But I think the question can also be answered (based on the video) like this...
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
If you use this one, the Teamtreehouse compiler will throw an error. It will not throw an error in xCode however.
Hope this helps!
kjvswift93
13,515 PointsYour second answer actually will not work because the dictionary currencies is declared as a constant, meaning that the the key-value pairs are immutable. You may capture a value in the dictionary, but you cannot remove or change the key-value pairs as long as the dictionary is declared as a constant. Besides, the challenge clearly asks you to CAPTURE one of the dictionary's values and assign it do a new constant, not MUTATE the original dictionary.
julian clarke
416 Pointsi resolved doing this let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = currencies["UK"]