Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,423 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
210,423 Points

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