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
Marvin Abella
6,378 PointsJavascript: arrays: Getting and setting Challenge 1 of 2
I'm stuck...here's the question:
The variable 'thirdElementInArray' was supposed to be the thrid element in the array. Fix the code so it 'thirdElementInArray' is the actual thrid element in the array.
<script>
var myArray = ["sugar", "rush", "fix", "thirdElementInArray", "it", 3.14, 42];
var thirdElementInArray = myArray[3];
</script>
I believe I did it right..do i have to put the actual array inside the myArray? I don't understand.
Bummer: Remember array indexes start with zero.
1 Answer
Kevin Korte
28,149 PointsHere is the hint it's giving you:
Bummer: Remember array indexes start with zero.
It wants it in the third spot. But myArray[3] is putting it into the 4th spot because the first spot is acutally 0, the second spot would be 1.
So you have to change that 3 to a different number.
Does that make sense?
Marvin Abella
6,378 PointsMarvin Abella
6,378 PointsThanks for tip Kevin, I got it right and I understood it, ... I knew what was happening, I got jumbled up with 3rd element and 3rd spot..I was counting from 0,1,2,3. Then I read it again, they want it ON the 3rd spot, if that made sense. Thanks again.
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsI've made the same error before too. Glad you got it!