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

Raeed Sabree
Raeed Sabree
10,664 Points

Inside the array literal, add three object literals. In other words, the objects array should have three values. Each

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 = [];
;
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Raeed Sabree Hi there! I wish I knew what you had tried already that's failing so that we can better help you to understand whatever it is that's not working. I feel like that it would provide a better learning experience for you than just handing over the solution. Can you give us some indication of what's not clear? Thanks! :smiley:

Raeed Sabree
Raeed Sabree
10,664 Points

Hey they want me array to have 3 values i tried var objects =[milk,eggs,cereal]; but that didnt work

1 Answer

Steven Parker
Steven Parker
231,269 Points

You need 3 object literals. Each of these needs two property/value pairs. Each pair wouldl have a property and a value, separated by a colon (:), and the entire object would be inside braces {}. And remember - 3 of those.

Also, if your values are to be strings, they must be in quotes (" or ').

Raeed Sabree
Raeed Sabree
10,664 Points

can you show me what it would look like?

Steven Parker
Steven Parker
231,269 Points

For example, ONE object literal might look like this:

{drink: "milk", food: "cookies"}

Your array will contain 3 like this, separated by commas (,), and the whole thing inside the brackets ([]) that you already have.

Raeed Sabree
Raeed Sabree
10,664 Points

for some reason its not working for me

Steven Parker
Steven Parker
231,269 Points

Update the script.js in your question above to show what you are writing as the challenge answer now.