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 Data Using Objects The Build an Object Challenge, Part 1 Solution

Justin Warren
Justin Warren
7,805 Points

Is this an okay format too?

var students = [
  {name:"Bo",track:"ios",achievements: 2, points:3}
  {name:"Moe",track:"web design",achievements:, points:}
  {name:"Jose",track:"java",achievements:2, points:4}
  {name:"Joe",track:"javascript",achievements:3, points:4}
  {name:"Toby",track:"ruby",achievements:4, points:5}
];
Patrik Horváth
Patrik Horváth
11,110 Points

it is :) but you have sall mistake your variable is INVALID because you miss "," after taking object to array

also learn use some SPACES after "," and : its more clear for other peoples when you will ask for help because giving random space after "," make feel bad

somewhere you have space and somewhere not its confusing for me =\

3 Answers

Michael Hulet
Michael Hulet
47,912 Points

Formatting is just style, and ultimately, style is up to you. The spacing here looks weird to me, but if you like it, that's what counts. That being said, if you're working with other people, you'll probably agree on a specific set of style rules, and I'd be willing to bet that this wouldn't be it, so be prepared for that. Like I said before, though, for the purposes of Treehouse code, what counts is that it works and you can understand it

Justin Warren
Justin Warren
7,805 Points

Thanks guys. Appreciate the feedback. Is more of a vertical formatting style a best practice?

Michael Hulet
Michael Hulet
47,912 Points

I'd say something like this is probably fairly standard, but it depends on the project:

var students = [
    {
        name: "Bo",
        track: "ios",
        achievements: 2,
        points :3
    },
    {
        name: "Moe",
        track: "web design",
        achievements: 3,
        points: 4
    },
    {
        name: "Jose",
        track: "java",
        achievements: 2,
        points: 4
    },
    {
        name: "Joe",
        track: "javascript",
        achievements: 3,
        points: 4
    },
    {
        name: "Toby",
        track: "ruby",
        achievements: 4,
        points: 5
    }
]

Personally, I tend to one-line it. Lots of people don't like it, but that's my style:

var students = [{name: "Bo", track: "ios", achievements: 2, points: 3}, {name: "Moe", track: "web design", achievements: 3, points: 4}, {name: "Jose", track: "java", achievements: 2, points: 4}, {name: "Joe", track: "javascript", achievements: 3, points: 4}, {name: "Toby", track: "ruby", achievements: 4, points: 5}];