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

Usen Ekpek
Usen Ekpek
1,634 Points

Arrays

Retrieve the 5th item and assign the result to a constant named value.

I have no idea what i am doing wrong.

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

1 Answer

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

You're doing brilliantly! You got 3 out of 4 steps correct. And I'm of the opinion that the first 3 steps were the most difficult. Now all you have to do is go into that array and get out the fifth element. Which in your case is 5. Most people start counting from 1. Computers and programming languages (at least most of them) start counting from 0. So if you need the fifth element, you have to look at the array at the index of 4. Index 0 has a 1. Index 1 has a 2 etc etc.

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

This is your code modified by one number! Hope this helps and hang in there :smiley: