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.

iOS Swift Collections and Control Flow Introduction to Collections Working With Arrays

Caleb Young
Caleb Young
711 Points

Am I putting this in right?

The question is asking me to remove index 5, which is 15, yet it is still telling me that I am wrong?

array.swift
// Enter your code below
var arrayOfInts = [1,9,8,90,76,15]

arrayOfInts.append(40)

arrayOfInts = arrayOfInts + [98]

arrayOfInts [4] = 76

let value = 76

arrayOfInts.remove(at: 5)

let discardedValue = 15 

1 Answer

Heidi Puk Hermann
Heidi Puk Hermann
33,354 Points

You are actually pretty close. instead of assigning 15 to the constant discardedValue, you should assign the removed value directly to the constant. Your code will look like this:

let discardedValue = arrayOfInts.remove(at: /*put your index number here*/)