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 trialJ P
1,620 PointsHi, I'm having trouble with 2-dimensional arrays. I get a There was an error with your code: TypeError: 'undefined''.
Hope you can help!
var coordinates = [ [1, 2] [0, 1] [1, 2] [0, 1] ];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Paras Bokhari
11,522 PointsHi Joseph,
You must add commas in order to separate each item within an array. That's why it's very common to enter each item in a two-dimensional array on a separate line.
const coordinates = [
[1, 2],
[0, 1],
[1, 2],
[0, 1]
];
console.log(coordinates) // logs the array.
Please note: the last item within an array will not have an ending comma.
Hope this helps.
KRIS NIKOLAISEN
54,972 PointsYour arrays should be separated by commas
J P
1,620 PointsThanks so much!