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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jake Mcnaughton](https://secure.gravatar.com/avatar/1510ef863f4ff4ef463cb423a1446144?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jake Mcnaughton
4,944 Pointschallenge says I'm removing the wrong item from array but I'm certain that i removed the correct one?
A challenge for Swift says I'm removing the wrong item from the array but I'm certain that I'm removing the correct one! :-(,
heres the question: Challenge Task 4 of 4
Great job so far! Clearly you know how to add and read items from the array so in this challenge let's try getting rid of a value.
For this task, remove the 6th item from the array and assign the result to a constant named discardedValue.
To remove an item, use the method removeAtIndex() and put the index number in between parentheses that you want to remove.
Heres my code:
// Enter your code below
var arrayOfInts = [1, 2, 3, 4, 5, 6]
arrayOfInts.append(7)
arrayOfInts += [8]
let value = arrayOfInts[4]
arrayOfInts.removeAtIndex(5)
let discardedValue = arrayOfInts
What am I doing wrong? D:
2 Answers
![Steven Deutsch](https://uploads.teamtreehouse.com/production/profile-photos/612592/micro_Unknown.jpg)
Steven Deutsch
21,046 PointsHey Jake Mcnaughton,
The problem is with the following code:
arrayOfInts.removeAtIndex(5)
let discardedValue = arrayOfInts
When you remove an item from an array using the removeAtIndex() method, it returns a value that it removed for use. You can store it in a variable or constant. In this case, you're doing nothing with the returned value. Then, on the next line you're assigning your updated array to the constant discardedValue. However, what you really need to be assigning is the removed item.
This is the solution:
let discardedValue = arrayOfInts.removeAtIndex(5)
Good Luck
![Paschal Ihenacho](https://secure.gravatar.com/avatar/e374e2edb3ed499c016995c9f553ff69?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Paschal Ihenacho
914 PointsarrayOfInts.remove(at:5) let discardedValue = arrayOfInts[5]
Jake Mcnaughton
4,944 PointsJake Mcnaughton
4,944 PointsOh I see it now!, thank you so much :)