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

Help with two-dimensional arrays

I was working on the coding challenge 'Create a two-dimensional array' when I ran into some trouble. I had had already completed tasks 1 and 2 out of 3, but I couldn't manage to pass Task 3. Here is my code:

var coordinates = [
 [2, 3]
 [2, 12]
 [7, 10]
 [4, 5]
];

It says 'Oops! It looks like Task 1 is no longer passing.' Here are the tasks:

  • Task 1 - In this code challenge you need to create a two-dimensional array -- an array of arrays. Start by creating an empty array literal named coordinates.
  • Task 2 - 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.
  • Task 3 - Add three more arrays to the coordinates array. The coordinates array should have 4 arrays in it -- each of those arrays should have 2 items in it.

Please help, Thank you.

5 Answers

Kevin Faust
Kevin Faust
15,353 Points

Looks like your only problem is that you forgot to put commas between each array

var coordinates = [ [1,2], [2,3], [3,4], [9,10] ];

Tom Nguyen
Tom Nguyen
33,500 Points

solution:

script.js
var coordinates = [
 [2, 3],
 [2, 12],
 [7, 10]
];

You forgot to add the commas after each of your arrays

EX: var coordinates = [ [2,3], [4,9], [6,8] ];