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 Working with Arrays

Jamie Redcay
Jamie Redcay
7,573 Points

"Make sure you're assigning the result of retrieving an item from the array to a constant named value"

"Make sure you're assigning the result of retrieving an item from the array to a constant named value" I got this error and am not sure what I'm doing wrong. Below is my code, please help.

var arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append(7) arrayOfInts += [8] arrayOfInts[4] = 9

arrays.swift
"Make sure you're assigning the result of retrieving an item from the array to a constant named value"
I got this error and am not sure what I'm doing wrong.
Below is my code, please help.

var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
arrayOfInts[4] = 9 

5 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're so close here, and you've done soooo well! You've even understood indexes in arrays :thumbsup: In fact, I'm just going to give you a hint from the instructions:

Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value.

Can you point to the part in your code where you have let value = ? :smiley:

Good luck! :sparkles:

Jamie Redcay
Jamie Redcay
7,573 Points
var arrayOfInts = [1,2,3,4,5,6]

arrayOfInts.append(7)

arrayOfInts += [8]

let firstTask = arrayOfInts[4]

arrayOfInts[4] = 9

I didn't have "let value = ?", but I'm still not sure where I'm going wrong

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Ok, thought you'd get it with the hint! Give this a go :smiley:

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

Happy coding! :sparkles:

Jamie Redcay
Jamie Redcay
7,573 Points
let value = arrayOfInts[4]  
let discardedValue = arrayOfInts.removeAtIndex(5)

I didn't learn this bit of coding i my training.

you used "value" where I had "firstTask" and the second "let" statement before "= arrayOfInts.removeAtIndex(5)"

I need to better understand how and when to string code together and why.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Yes, I used <value>. Again, here is the quote from the instructions:

"Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value."

The last line is for the last step in the challenge.

Jamie Redcay
Jamie Redcay
7,573 Points

LOL, I was on step 3 of 4 in the code challenge the next step had me create the last line of code. that makes more sense now. Thanks