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 trialIngrid Stevens
1,651 PointsAccording to the problem, both currencies and ukCurrency need to be constants, however ukCurrency is changing currencies
According to the problem, both currencies and ukCurrency need to be constants (let), however ukCurrency is changing currencies and making it so that there is a mutable error. If you were to let the challenge accept currencies as a var, it would be compiled correctly, but then you get the error of "let currencies needs to be defined".
This is what it wants: let currencies = ["US":"Dollar", "UK":"Pound", "JP":"Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
This is what works:
var currencies = ["US":"Dollar", "UK":"Pound", "JP":"Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
Treehouse, can you fix this so I can correctly answer the question?
let currencies = ["US":"Dollar", "UK":"Pound", "JP":"Yen"]
let ukCurrency = currencies.removeValueForKey("UK")
2 Answers
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 of 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 dictionary itself
Ingrid Stevens
1,651 PointsThanks. I just reread the problem and realized that it was asking for the value of UK. Solved it and came back here.
But thanks again for your quick response!