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

help. I don't understand what is wrong

help. I don't understand what is wrong

array.swift
// Enter your code below
var arrayOfInts: [Int] = [0, 1, 2, 3, 4, 5] 
arrayOfInts.append(6)
arrayOfInts = arrayOfInts + [7]
arrayOfInts[4] 
let value = 
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

This question was already posted to the Community ~2 hours ago. Duplicate question has been deleted. Please refrain from posting duplicate questions in the Community, especially in a short time frame as that.

Jason ~Treehouse Community Moderator~

1 Answer

Matt Skelton
Matt Skelton
4,548 Points

Hey Eric,

Simple fix for this one, at the moment your statements don't quite match up. You're currently getting the correct value from the array, though you aren't actually assigning it to your new variable.

Typically when assigning a value to a variable, you'll need to make sure that the value you are assigning comes on the right hand side of a given equation. Likewise, the variable you are assigning to will need to be on the left hand side of the equation.

With this in mind, let's tweak your code a little:

var arrayOfInts: [Int] = [0, 1, 2, 3, 4, 5] 
arrayOfInts.append(6)
arrayOfInts = arrayOfInts + [7]

let value = arrayOfInts[4]    // Corrected Assignment

And there we have it! You've found the value located at this index in the array and stored it in a new variable named value.

Hope this helps, keep coding!