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 trialPeter Hearty
9,854 PointsJavascript 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
8,378 PointsArray 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]);
Unsubscribed User
6,144 PointsYou have to use a number inside the brackets.
Michael Brown
7,431 PointsI 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.
Unsubscribed User
6,144 PointsThe number 3 is the correct answer but don't forget to add the alert before the parentheses.
Michael Brown
7,431 PointsOhhhhh. 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
7,119 Pointsno its not! alert 3 should be the answer? it's not? anyone care to enlighten me??!?!?!?!?!?~!?
Lee Puckett
12,539 PointsI was making the mistake of typing in the brackets, but they are already there.
Prsicilla Anesu Muzerengwa
12,577 Pointsvar messages = [ "Hello", "Welcome", "JavaScript!", "Arrays are awesome", "Goodbye"]; alert( messages[3] );