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 trialSara Worth
5,225 PointsStill need help on this question
I can't figure out how to add elements from the array to the dictionary. I've re-watched the videos and looked for the answer online but I'm still doing something wrong.
NSArray *shoeOrder = @[@"Charles Smith", @(9.5), @"loafer", @"brown"];
NSMutableDictionary *shoeOrderDict;
shoeOrderDict = [[NSMutableDictionary alloc] init];
shoeOrderDict[@“customer”] = @[shoeOrder objectAtIndex: 0];
shoeOrderDict[@“size”] = @[shoeOrder objectAtIndex: 1];
shoeOrderDict[@“style”] = @[shoeOrder objectAtIndex: 2];
shoeOrderDict[@“color”] = @[shoeOrder objectAtIndex: 3];
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Sara,
Your code is 100% correct... the problem lies with the quotation marks around the four values (the last 4 lines of code). If you notice in the code above, they are highlighted, and in the Challenge Editor, I'm betting the strings weren't color formatted like the strings in the first line of code. This is because these quotation marks are "fancy quotes" and are not recognized by the code engine as being actual quotes (I'm guessing you copy/pasted from another editor into the challenge?).
So, all you need to do is go and change those quotes to regular quotes (just delete and type in from the challenge), and all three tasks will pass. Keep this in mind when doing a copy/paste (which there is nothing wrong with). The quotes may not be 'real' quotation marks.
Edited: Please see comment below for an additional syntax error not seen when this was first answered.
Also, just a tip to keep things DRY. You could do these 2 lines:
NSMutableDictionary *shoeOrderDict;
shoeOrderDict = [[NSMutableDictionary alloc] init];
as one line:
NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc]init];
Keep Coding! :)
Sara Worth
5,225 PointsSara Worth
5,225 PointsHmm... I tried re-typing everything and it still doesn't pass.
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsSorry Sara Worth
I kind of focused on the quotes and missed that you have the @ symbol before the array
objectAtIndex
lines which is not correct. These don't need the @ symbol as they are retrieving information rather than creating the object. Soshould be
My apologies for the confusion.
Sara Worth
5,225 PointsSara Worth
5,225 PointsThank you - that worked!