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 Collections and Control Flow Introduction to Collections Working With Arrays

Reading from array and creating new constant. Need help with 3rd part of this question.

I understand about adding arrays and reading from them, However cannot understand why I am not passing this stage of the challenge.

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

arrayOfInts[5]

let value = arrayOfInts[5]
Jenna Dercole
Jenna Dercole
30,224 Points

Hi Connor,

Array indexes start at 0, not 1, so the value you're currently passing would return the sixth element, not the fifth. You know what to do! ;)

1 Answer

Patrick Duhamel
Patrick Duhamel
5,786 Points

Array elements starts at 0, not 1. This means that 0 is the 1st element, so to get to the 5th element, you actually ask for the element at position 4 of the array.