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
Alia Khan
3,733 PointsReading Arrays in Swift
Hi in terms of reading arrays I feel like I understand them. In the video we learnt that array indexes start at 0 e.g. var animals = ["Cat", "Dog", "Frog"] The index for cat would be 0 Dog would be 1 and Frog would be 2
however in the challenge video the correct answer confuses me
The 3rd task is to retrieve the 5th item from the array and assign the result to a constant named value var arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append(7) arrayOfInts += [8] let value = arrayOfInts[6]
in the list of numbers the index for 1 =0 2=1 3=2 4=3 5=4 6= 5 7=6
the 5th item is the number 6 as it has an index of 5 however in the challenge the correct answer is 4
could anyone please explain
thanks you
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! When they say the ordinal numbers they mean like we humans say it. Here's a quote from your question:
the 5th item is the number 6 as it has an index of 5
But given this array arrayOfInts = [1,2,3,4,5,6] The first item is 1. We don't say the zeroth item So the second is two and so forth. So in this example the fifth item is 5 which is at an index of 4. Hope this helps!
Alia Khan
3,733 PointsAlia Khan
3,733 Pointshaaha ok Got It! so the 5th item that the challenge was referring to was actually the fifth item as in the number 5 it wasn't the index number 5 . That's why I thought at index number 5 the answer would be 6
I understand that now Thank you :D