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 What is an Array?

analyn jane calado
analyn jane calado
3,523 Points

the starting variable of creating an array

should i used the var key word always, if i have to create an array?

Analyn,

question 2. Leave the data array in place. Add another line of code that creates a second array named assorted. Assign one string value, a number and a Boolean value (like true or false) to the array. The complete assorted array should have 3 values total.

are you still having problems with this question?

5 Answers

Nathan Heffley
Nathan Heffley
19,878 Points

To create a new array called "shoppingList" that has the items "carrots" "milk" and "eggs" in it, you would use this code:

var shoppingList = ["carrots", "milk", "eggs"];

The var keyword is used because you are creating a new variable. An array is just a more complicated variable that what you are used to. You only use the var keyword when you are creating the array. Once you have created the shoppingList array you will not need to put the var keyword in front of it again.

Analyn- I am still learning Javascript but this is a quote from one of my coding textbooks: "An array is a variable containing multiple values. Any variable may be used as an array." So if an array is a variable then it would need to be identified as var.

Hi Analyn, you should use always use the var keyword when creating a new array. It looks like this:

var fruits = [apple, banana, pear, strawberry];

analyn jane calado
analyn jane calado
3,523 Points

in my workspace in this lesson, why it's not working?

For that lesson, I was able to complete the exercise with this answer: var data = [1, 2, 3];

analyn jane calado
analyn jane calado
3,523 Points

yeah i got it.. aahhmmm,..... when i asked u, i tried that answer, and it works!!

analyn jane calado
analyn jane calado
3,523 Points

I'm am now in the 2nd challenge,... i can't completely understand the question.

I watched the video and was also having trouble with that one. Once I reviewed the video the answer came to me. If you do the following, you should pass the 2nd part of the challenge without a problem:

var assorted = ['apples', 99, true];

You can assign different values than what I have and it should work. Hopefully, this helps.