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 trialNeslee Rodillo
19,615 PointsI don't understand the issue
Question: "The variable 'thirdElementInArray' was supposed to be the third element in the array. Fix the code so it 'thirdElementInArray' is the actual third element in the array."
Answer (given in the working area):
var my_array = ["sugar", "rush", "fix", "it", 3.14, 42];
var thirdElementInArray = my_array[3];
4 Answers
Christer Austad
8,373 PointsHi,
Arrays in Javascript and most other programming languages use zero-based indexing. This means that when counting the order of items in the array, you need to start with 0.
var array = ['first', 'second', 'third'];
var firstElementInArray = array[0]; // First element has the index of 0 - zero
var secondElementInArray = array[1];
var thirdElementInArray = array[?]; // Replace ? with the correct number.
Neslee Rodillo
19,615 PointsGreat thanks :), I am new to javascript so its taking a while to get the hang of all the details.
Thanks for the explanation
Apologies if my issue seems trivial :S
Dino Paškvan
Courses Plus Student 44,108 PointsYou needn't apologize for asking questions. This is a place for learning. :)
Good luck with the rest of the course.
Neslee Rodillo
19,615 PointsThank you Dino :)
Togzhan Kurmanbek
2,077 Pointsvar myArray = ["sugar", "rush", "fix", "it", 3.14, 42]; var thirdElementInArray = myArray[2];
Well done! You're doing great! Next task