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 trialIstvan Burgyan
509 PointsHow can I change a constant? This doesn't make any sense?
The challenge is : Let's create a dictionary that contains the currencies of the various countries along with their country codes. The country code will be the key and the currency the value. Using the following key-value pairs: US : Dollar, UK : Pound, JP : Yen assign them to a constant named currencies.
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] CORRECT
The next challenge states: Assign the value for key "UK" to a constant named ukCurrency.
HOW DO YOU CHANGE A CONSTANT??????? IT DOES NOT MAKE SENSE TO ME?
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
1 Answer
Stone Preston
42,016 Pointsyou misinterpreted what the task is asking you to do.
task 2 states: Assign the value for key "UK" to a constant named ukCurrency.
you dont change the value assigned to the key "UK", you assign the value corresponding to that key to a new constant:
let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies["UK"] // ukCurrency now has a value of "Pound"
// currencies remains unchanged, with a value of [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]
this does not modify the currencies dict at all, you just access a value from it. nothing in the dictionary changes. you are basically saying "give me the value that corresponds to this key, and assign that value to this constant". it doesnt change anything about the constant dictionary itself
Istvan Burgyan
509 PointsIstvan Burgyan
509 PointsDoh! I get it now. Thank you for taking the time to answer my question.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsawesome glad that cleared things up