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 trialMehran Amini Tehrani
1,523 PointsDictionary
Hello,
How can I Assign the value for key "UK" to a constant named ukCurrency?
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrencey = ["UK": "Pound"]
6 Answers
Mehran Amini Tehrani
1,523 PointsIt should be like this:
let ukCurrency = currencies["UK"]
Petar Popovic
Courses Plus Student 23,421 PointsWell, you already did that :) You assigned key "UK" for value "Pound" to constant name ukCurrencey
Mehran Amini Tehrani
1,523 PointsYes, but it gives me an error "You need to define 'let ukCurrency' ". How can i define it?
Petar Popovic
Courses Plus Student 23,421 PointsIt gives you an error because you made spelling mistake. You wrote ukCurrencey, what you need to write is ukCurrency
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = ["UK": "Pound"]
Edwin Rivera
924 PointsIve tried doing it that way and i get " Your code could not be compiled. Please click on "Preview" to view the compiler errors." when i check the preview there's nothing, Im i doing something wrong?
Petar Popovic
Courses Plus Student 23,421 PointsTry to copy my code. Does it pass?
Edwin Rivera
924 PointsI was misunderstanding the question in general, the answer was: let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = currencies["UK"]
Petar Popovic
Courses Plus Student 23,421 PointsPetar Popovic
Courses Plus Student 23,421 PointsMehran you are right. I wanted to write the same but I forgot to change it when I copied your code and didn't see that until you said. I am happy you found a solution.
Happy coding and keep learning
Mehran Amini Tehrani
1,523 PointsMehran Amini Tehrani
1,523 PointsThanks bro...!
Mehran Amini Tehrani
1,523 PointsMehran Amini Tehrani
1,523 PointsThanks bro...!
Mehran Amini Tehrani
1,523 PointsMehran Amini Tehrani
1,523 PointsThanks bro...!