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

how do I make this code correct with respect to the task?

tried several versions to accomplish getting the code correct. I keep missing out

script.js
var objects = {
    fruits: ['mangoes', 'oranges', 'apples'],
    vegetables: ['carrots', 'spinach', 'cabbage'],
    price: [55]
};
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

andren
andren
28,558 Points

The task is to create an array with three objects with two values. You have created 1 object with 3 properties containing arrays.

Here is an example of what the challenge is looking for:

var objects = [
  {property1: "prop 1", property2: "prop 2"},
  {property1: "prop 1", property2: "prop 2"},
  {property1: "prop 1", property2: "prop 2"}
];

There is one array which contains three objects, each object contains two properties. The name of the properties and what they contain is irrelevant to the challenge, as long as there are three objects which each contain two properties your code will pass.