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 trialFaizan Mohammed
2,036 PointsNot able to get through the challenge.
What's wrong in my code?
NSMutableArray *elements=[NSMutableArray array];
[elements addObject:@"Helium"];
[elements addObject:@"Neon"];
[elements addObject:@"Argon"];
[elements removeObject:@"Neon"];
[elements removeObjectAtIndex:2];
4 Answers
Faizan Mohammed
2,036 PointsGot the answer. The syntax is [elements removeLastObject]; . Thank you guys for the help.
eirikvaa
18,015 PointsYou only have two objects in your array (after deleting "Neon"), and are trying to delete object number three, which doesn't exist. Remember that the index starts at 0 in an array, so index 2 would be the third object.
Kyle Pontius
6,190 PointsI agree with Eirik, you're accessing an index that has been deleted. At the point that the final line executes, you should only have 0 and 1 as available indices.
Faizan Mohammed
2,036 PointsI have changed it to [elements removeObjectAtIndex:1] and even then it does not work . it says a method must be called on the "elements" array to remove the last object.
Faizan Mohammed
2,036 PointsThe new code is NSMutableArray *elements=[NSMutableArray array]; [elements addObject:@"Helium"]; [elements addObject:@"Neon"]; [elements addObject:@"Argon"]; [elements removeObject:@"Neon"]; [elements removeObjectAtIndex:1];
James Rowe
2,551 PointsJames Rowe
2,551 PointsAhhhhh thank you!!