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 trialMitchell Warmerdam
4,225 PointsAssigning 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
10,101 PointsHi 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. :-)
ille
2,275 Pointssometimes this stuff really confuses me! this really is getting frustrating spending 30 mins trying to figure it out! thanks for the solution
Dimang Chou
4,697 PointsThanks for your solution.
ALAN SALDANA
357 Pointsthat doesn't work at all
Kellington Chidza
866 Pointslet value = arrayOfInts[4]
Quentin Jobs
UX Design Techdegree Graduate 23,599 PointsFirst 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.
Robert Brown
12,269 PointsRobert Brown
12,269 PointsWhere 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"
leonardmichalas
601 Pointsleonardmichalas
601 PointsHey, 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".