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 trialAndrew Pandaleon
311 Pointsconstant vs. variable in dictionaries:
In the dictionaries challenge it has me identify the currencies dictionary as a let rather than a var. So when I enter currencies.removeValueForKey(UK") it comes up immutable.
Please advise.
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrencies = currencies.removeValueForKey("UK")
1 Answer
Jayden Spring
8,625 PointsLet is a constant, constants are immutable. You want a variable array i.e a var
Andrew Pandaleon
311 PointsI understand that. In the dictionaries challenge it requires you to create a constant dictionary called currencies. Then it requires you to change it and currencies.removeValueForKey to a new constant called ukCurrency. I'm wondering how to do this or if the challenge itself is flawed?
Jayden Spring
8,625 PointsIf you have a look at my screenshot here
The dictionary itself is mutable unless you want it to be immutable (ie fixed) so therefore is a var. You can then remove the key value pair and store the value to a constant.
Jayden Spring
8,625 PointsI have just looked at the challenge and it is not asking you to remove the item from the array but assign the value of 'UK' to a constant named uk currency.
Therefore all you need to do is let ukCurrency = currencies["UK"]
Andrew Pandaleon
311 PointsAndrew Pandaleon
311 PointsYes I get that the dictionary is a variable if its identified as such with var. However, it's a two part challenge. It will not let me complete the first part without assigning the dictionary as a constant. Therefore I cannot change it, as required, in the second part. This is maddening.