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

iOS Swift 2.0 Collections and Control Flow Introduction to Collections Manipulating an Array

problem with code challenge

After task 1, in task 2, I get this error when I click check work:

Oops! It looks like Task 1 is no longer passing.

can you please let me know why I keep having this?

Jhoan Arango
Jhoan Arango
14,575 Points

Hey Amal,

If you can please post the code you are trying to pass the challenge with here. That way we can see what it is that it's happening.

Hello Jhoan Arango

this is the code:

// Enter your code below

var arrayOfInts = [0,1,2,3,4,5,6]

arrayOfInts.append(7)

arrayOfInts += [8]

thanks

5 Answers

Tommy Choe
Tommy Choe
38,156 Points

Hey Amal, looks like task 1 isn't passing because you have 7 numbers in your array now not 6. Task 1 wants you to provide an array with just 6 numbers.

Have fun coding!

Tommy Choe I have no idea how I missed it!!!

Thank you for your help

Tommy Choe
Tommy Choe
38,156 Points

Haha yeah I didn't notice it at first either. I had to compare my answer to yours in order to spot the difference. Anyways, I'm glad I could help!

Tommy Choe Can you help me with this The question is: 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.

This is what I did: var arrayOfInts = [1,2,3,4,5,6]

arrayOfInts.append(7)

arrayOfInts += [7]

let value = arrayOfInts [4]

arrayOfInts.removeAtIndex(7)

let discardedValue = arrayOfInts

but I'm getting an error, Please help!

Michel Ådefjäll
Michel Ådefjäll
Courses Plus Student 695 Points

I'm getting the same error, but I can't se any wrong with my code. What could i do?

var arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append(7) arrayOfInts += [8] let value = arrayOfInts[4] arrayOfInts.removeAtIndex(5) let discardedValue = arrayOfInts

  1. arrays start with 0 so be careful when counting to remove 6th item. /////2. you assigned the array name to the constant discardedValue but you are suppose to put the method removeAtindex for that constant

I think your problem can be found in the video. As you remember, arrays always start with 0, but both of yours' happen to start with one. So, try doing (0,1,2,3,4,5) instead and see if that will work.