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 trialRobert Harmon
1,464 PointsStuck on "Dictionaries" challenge task 2 of 2. Have I made an error?
The challenge is to "Create a constant named ukCurrency. Assign the value from the currencies dictionary. Use the key of "UK" to access the value."
This is what I have so far :
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = currencies.removeValueForKey("UK")
What am I missing? Thanks in advance!!
3 Answers
Steve Hunter
57,712 PointsHi Robert,
Your code changed the dictionary. You removed a key/value pair.
The tests for this challenge will test that the value of your ukCurrency
variable is as expected and that the dictionary itself remains unaltered. Your code created an outcome different to the one expected.
Make sense?
Steve...
Robert Harmon
1,464 PointsSomeone else asked the same question. The correct second line of code is:
let ukCurrency = currencies["UK"]
Robert Harmon
1,464 PointsAlthough, I'm still a bit confused as to why the code I tried the first time doesn't work. Can anyone explain?
Robert Harmon
1,464 PointsRobert Harmon
1,464 PointsAh, got it! So even though I assigned ukCurrency the correct value by removing "Pound" from the dictionary, the test expected the dictionary to remain unaltered (to continue to contain the value "Pound"), and thus my code became incorrect. Right?
Thanks, Steve!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsSpot on, yes. :-)