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

mixing and matching arrays and objects

Inside the array literal, add three object literals. In other words, the objects array should have three values. Each object should have 2 property/value pairs.

script.js
var objects= [
  {name;'kura',
  grade; [2,2]}

];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

Erik McClintock
Erik McClintock
45,783 Points

Hello,

If you recall, objects in JavaScript act as associative arrays; that is to say they are data structures of key/value pairs, as follows:

var person = {
    name: "Erik",
    profession: "Web Developer"
};

In the example above, our object is named "person", and inside that object, we have two properties: "name" and "profession", and those properties have the values "Erik" and "Web Developer", respectively. Note the syntax, including that properties are comma separated - this is one of the rare instances where you want to make sure you do not end your lines with a semi-colon!

The task in this challenge asks you to create an array that will have three items in it. Each of those items needs to be an (unnamed) object, and each of those objects needs to have two key/value pairs inside, like in my example above.

With this clarifying information and example of an object, please try the challenge again. If you need more help, please post the new code that you try and I can continue to walk you through it.

Erik

thanks i got what you are saying. this is how i did it

  var person =[
 { name: "Erik",
    profession: "Web Developer"
},
{ name: "kura",
   due = ' 21/02/2015'},
{ name: "trish",
    assignment: " finish JavaScript Loops, Arrays and Objects"
}
];
;
Erik McClintock
Erik McClintock
45,783 Points

You've got an extra semi-colon at the end but that should be fine; looks good!

Happy coding!

Erik

thank you so much