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 trialJake N
612 Pointsi can't figure out part 2 of this challenge, it says i need to use something about the option, but that wasn't shown?
i have been trying
let ukCurrency = "UK" and it isn't it
let currencies = ["US": "Dollar", "UK": "Pound", "JP":"Yen"]
let ukCurrency = ("Optional("UK")")
1 Answer
Stone Preston
42,016 Pointstask 2 states: Assign the value for key "UK" to a constant named ukCurrency.
you can access values for keys in dictionaries by using subscript syntax which means placing the key in between brackets after the name of the dictionary:
let someValue = someDict["someKey"] // returns the value for the key of "someKey" in someDict
you need to access the value in the currencies dict with a key of "UK".
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies["UK"] // ukCurrency now has a value of "Pound"
see the Swift eBook for more information on accessing and modifying dictionaries