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

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Review Array Basics

Where wrong in this insert quiz

I asked complete the code to alert message and inside brackets message

var messages = [ "Hello", "Welcome", "JavaScript!", "Arrays are awesome", "Goodbye"];
alert( messages[4] );

2 Answers

Andreas Nyström
Andreas Nyström
8,887 Points

Hi.

They want you to alert "arrays are awesome". An array starts at position zero, and that means:

var messages = [ "Hello", "Welcome", "JavaScript!", "Arrays are awesome", "Goodbye"];

alert( messages[0] ) = 'Hello';
alert( messages[1] ) = 'Welcome';
alert( messages[2] ) = 'JavaScript!';
alert( messages[3] ) = 'Arrays are awesome';
alert( messages[4] ) = 'Goodbye';

So as you can see an array always starts at index 0 and not 1. Make sure you're getting this :)! Happy coding!

Wonderful explanation. Thanks. I really appreciate it and happy coding

Antonio De Rose
Antonio De Rose
20,884 Points
//arrays are 0 based, meaning, they start from 0 index, and 1st index
//if you are new to arrays, I'd suggest you to have a good grasp on arrays
var messages = [ "Hello", "Welcome", "JavaScript!", "Arrays are awesome", "Goodbye"];
alert( messages[4] );