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

Assigning results to a constant named value in Swift

Hi! I'm stuk on this challgenge:

Challenge Task 3 of 4

We also learned about reading values from an array. Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value.

My code is:

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

arrayOfInts.append(7) arrayOfInts += [8]

arrayOfInts[4] = "constant"

6 Answers

Michael Reining
Michael Reining
10,101 Points

Hi Mitchell,

The problem is in your last line of code.

The challenge asks you to create a new constant called "value" and assign the 5th item of the array to the new constant.

// Enter your code below
var arrayOfInts = [0,1,2,3,4,5]
arrayOfInts.append(6)
arrayOfInts += [7]

// Let's break it down
// Create new constant called "value"
// Set it's value to the 5th item of the integer array

let value = arrayOfInts[4]

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift

Where did you "value" as a key word to use? There was nothing like this used in the videos.

Was stock on this for over half hour and still don't see where I would have found the use of "value"

Hey, I stucked at the same point because I named my constant "result". Writing the name of the constant in " " might be less confusing.

So I think the task should be like this:

We also learned about reading values from an array. Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named "value".

sometimes this stuff really confuses me! this really is getting frustrating spending 30 mins trying to figure it out! thanks for the solution

Dimang Chou
Dimang Chou
4,697 Points

Thanks for your solution.

ALAN SALDANA
ALAN SALDANA
357 Points

that doesn't work at all

let value = arrayOfInts[4]

First I had: arrayOfInts[4] let value = arrayOfInts[4] I wrote this code because I thought that I had to show where/how I retrieved the 5th item. So I was stuck on this for ages unless I took out my first line and left the second.