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 trialROB TILLEY
842 PointsAssign the value for key "UK" to a constant named ukCurrency.
Tried the answers on the discussion forum but does not work. The question is not asking for anything that was covered in the training. Need help pls.
let currencies = ["US":"Dollar","UK":"Pound","JP":"Yen"]
let ukCurrencies = currencies["UK"]
2 Answers
kjvswift93
13,515 PointsYou have it right with the exception of one typo: You have assign the value for the key "UK" to 'ukCurrencies', it needs to be ukCurrency.
let currencies = ["US":"Dollar","UK":"Pound","JP":"Yen"]
let ukCurrency = currencies["UK"]
Jon Schenck
2,028 PointsYour second constant needs to be changed. It should look like this...
let ukCurrency = Pound
Jon Schenck
2,028 PointsIf this is helpful I would appreciate it if you click best answer. Thank you.
kjvswift93
13,515 PointsJon, although this will pass the challenge, it isn't exactly what the question is asking you to do. This is all about capturing values, so even though "Pound" is the value for the key "UK" and therefore technically a satisfying answer to the compiler here, assigning the value for the key in a dictionary to a new constant is not the same as simply assigning that key's value String as itself to a new constant. It needs to be like this
let someConstant = someDictionary["someKey"]
Jon Schenck
2,028 PointsSo basically whatever makes the value equal to pound is what will make the compiler accept the answer. I see what you have done. Thank you for further explaining this. I appreciate it.
ROB TILLEY
842 PointsROB TILLEY
842 PointsThanks Kyle. As an attempt to understand what is going on here, does this code look into the constant named "currencies" find the value for the code "UK" and then use it as a value for a newly created constant named "ukCurrency"?. If yes, what would be a real world example of why you would want to do this?