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 Create an Array

JavaScript Loops, Arrays, and Objects: Tracking Multiple Items with Arrays Challenge Task 1 of 2

The challenge instructions state "Create and array named data and store any three numbers in it".

The previous video ended with a walk-through of a simple array to illustrate the syntax. I understood it as follows:

var ___ = {
'__', 
'__', 
'__', 
};

I answered the challenge as follows:

var data = {
  '4',
  '66',
  '987',
};

and received a SyntaxError stating that the commas were incorrect. I tried turning the numbers into strings, using " instead of ', eliminating the ' or " entirely, replacing the , with ; and removing the ; after the closing curly brace. I knew that these changes wouldn't be the correct answer but I was interested in the error I would receive. All errors were the same but replaced the thing causing the error with whatever I had just changed.

Can anyone help me understand what I'm doing wrong here? Thanks.

3 Answers

Answered it myself. I didn't realize the instructor was using [] instead of {}. Those tiny things always get me.

Steven Parker
Steven Parker
231,269 Points

The instructions say "Create an array named data and store any 3 numbers in it."

I see 3 issues:

  • arrays are enclosed with brackets [] (braces {} are used for objects)
  • putting something in quotes makes a literal string, numbers should have no quotes
  • items are separated by commas, but there should not be a comma after the last one

Thanks Steven - I made all those changes and it works.

Steven Parker
Steven Parker
231,269 Points

Anna Gallishaw — Glad to help. You can mark the question solved by choosing a "best answer".
And happy coding!