Bummer! You must be logged in to access this page.

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

Two Dimensional Array Challenge Help

Hi All,

I am a little stuck on the coding challenge for this video

The task is:

A two-dimensional Array is an array of arrays. Add 1 array to the coordinates array. That new array should have two items in it.

I've tried various ways of amending my array but no luck. Am i doing something wrong?

My latest code is as follows.

var coordinates = new Array()

coordinates[ [0, 'test']

];

However this flags up with the error:

Bummer! There should be one item in the coordinates array.

Any help would be appreciated. Thanks

2 Answers

A variable can contain an array when it's declared, but the way to do it is to use the []. So for coordinates, you would say

var coordinates = [];

That creates an empty array. You can then add arrays into with a method like push. So you can type something like

coordinates.push(['north', 'west']);

So then coordinates is an array which contains a single array of ['north', 'west'] .

[['north', 'west']]

You can continuously push arrays into the coordinates variable and they will be independent arrays contained in the parent array.

coordinates.push(['north', 'west']);