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 trialAndreas Parsley
442 PointsHow do you change the Key from "UK" to "ukCurrency"
I know one way of doing it but that would have me go back into the constant and change it...
I know there is a different way...
I really need some help
// Country Code Currency
// or
// Key Value
// Country Currency
// US Dollar
// UK Pound
// JP Yen
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = ["Pound"]
2 Answers
miguelcastro2
Courses Plus Student 6,573 PointsRemember that dictionaries are key/value pairs. The first portion being the key and the portion following the ":" being the value:
let dictionary = [ "Key": "Value"]
// Change key from US to UnitedStates
// Before
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
// After
let currencies = [ "UnitedStates": "Dollar", "UK": "Pound", "JP": "Yen"]
// Change value from Dollar to $
// Before
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
// After
let currencies = [ "US": "$", "UK": "Pound", "JP": "Yen"]
Hope this helps.
Riley Spencer
1,753 Pointslet ukCurrency = ["UK']