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

Heidi Toft
Heidi Toft
1,894 Points

how to assign the result to a constant named value

I am unsure how to assign the result to a constant.

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

3 Answers

Ashley Williams
Ashley Williams
740 Points

Hi, Are you trying to add 7 onto the array? If so use the Array.push(7); Also what value are you trying to assign to the constant? The variable declaration for constants is: const yourVariableName;

Heidi Toft
Heidi Toft
1,894 Points

Yes, I was trying to add 7, but I have not learned .push. I had to get rid of the line arrayofInts[4] and then it worked. Thank you!

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Heidi,

The challenges seems to be experiencing a tech glitch at the moment, so I cannot verify my answer.

If I remember the challenge correctly, you just have an extra line of code >>>

arrayOfInts[4]

If you delete that line (it's not doing anything anyways, and keep the one below it, which is assigning that value to the constant.

Hopefully that was the problem. Let me know. :)

Keep Coding! :dizzy:

Heidi Toft
Heidi Toft
1,894 Points

You were right. I removed that line and it worked. Thanks for your help!

Thomas Dobson
Thomas Dobson
7,511 Points

Hi Heidi,

as previously mentioned you have an extra line of code. remove:

arrayOfInts[4]

This will remove the compiler error you are seeing.

step 4 is asking you to remove the 6th item in your array and assign it to a constant named discardedValue. this can be accomplished by:

let discardedValue = arrayOfInts.remove(at: 5)

I hope this helps.

Heidi Toft
Heidi Toft
1,894 Points

I got rid of the extra line and was able to fix it. Thanks for your help!