Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Faizan 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!!