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

Peter Hearty
Peter Hearty
9,854 Points

Javascript loops, arrays and objects. Quiz question 1 of 5

The question asks to finish the code below to open an alert with the message "arrays are awesome". The code in the question is like this;

var messages = ["hello", "welcome", "Javascript!"; "arrays are awesome", "Goodbye"];

_______ (messages[ ]);

I would have thought the answer is:

alert(messages["arrays are awesome"];

Can anyone help me

6 Answers

Abe Layee
Abe Layee
8,378 Points

Array index starts from 0 up. We human start at one but computers start at 0. In order to alert " arrays are awesome", you need to find the index of it. so from 0,1,2,3,4. In this case is 3. So you want to pass the number 3 into the brackets. like this

var messages = ["hello", "welcome", "Javascript!"; "arrays are awesome", "Goodbye"];
alert (messages[3]);

You have to use a number inside the brackets.

I agree the answer is "3". But Treehouse doesn't agree with us:

Finish the code below to open an alert with the message "Arrays are awesome" in it:

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

( messages[    ] );

I answered with the number "3" and the response was: "Bummer! Unfortunately, that answer is incorrect."

But I think "3" is the correct answer.

The number 3 is the correct answer but don't forget to add the alert before the parentheses.

Ohhhhh. Thanks, Antoine. I didn't see an "answer blank" ahead of "( messages [ ] );" to clue me into filling in 2 blanks, though I should have seen the indentation and parenthesis and realized something should go in front of those parenthesis.

 var messages = [ "Hello", "Welcome", "JavaScript!", "Arrays are awesome", "Goodbye"];
           ( messages[           ] );
Rich Braymiller
Rich Braymiller
7,119 Points

no its not! alert 3 should be the answer? it's not? anyone care to enlighten me??!?!?!?!?!?~!?

I was making the mistake of typing in the brackets, but they are already there.

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