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 trialDejan Zivanovic
613 PointsI need help on challenge task 2 of 2, What is a Dictionary?
I need help on challenge task 2 of 2: How do I assign the value for key "UK" to a constant named ukCurrency?
I wrote this: let ukCurrency = ["UK"] but i got wrong answer.
all together is:
- let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
- let ukCurrency = ["UK"]
2 Answers
Holt Hunter
4,629 PointsHere is your dictionary:
let currencies = ["US" : "Dollar", "UK" : "Pound", "JP" : "Yen"]
To access an item in a dictionary you use the key instead of the position, for example:
println(currencies["UK"])
This would print "Pound", because it is located at the "UK" index. So to assign "Pound" to ukCurrency you would need to do this:
let ukCurrency = currencies["UK"]
That assigns "Pound" to ukCurrency which is what the quiz wanted you to do.
Andres Oliva
7,810 PointsYou need to specify the dictionary as well, not only the key.
This is what it should look like:
let ukCurrency = currencies["UK"]