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 Accessing All of the Properties in an Object

i've tried every suggestion

i've tried every suggestion and it still won't work

script.js
var shanghai = {
  population: 14.35e6,
  longitude: '31.2000 N',
  latitude: '121.5000 E',
  country: 'CHN'
};for (var something in shanghai){
    console.log(something + ': ' + shanghai[something]);
 console.population.shanghai
console.longitude.shanghai
console.latitude.shanghai
console.country.shanghai
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
James George Williams
James George Williams
4,364 Points
var shanghai = {
  population: 14.35e6,
  longitude: '31.2000 N',
  latitude: '121.5000 E',
  country: 'CHN'
};
for (var something in shanghai){
   console.log(something + ': ' + shanghai[something]);
}

The for in loop iterates over all the properties of your object. That means you only need the first console.log statement.

The subsequent 4 statements in your loop try to access a property of the console object. This is not what you want.

The first statement will log everything to the console.

2 Answers

I've tried that james. the second part of the objective insists on 4 actual lines. there is no answer that works. the answer you gave works for the first part of the objective. not the second. it says log out every line

James George Williams
James George Williams
4,364 Points

Hi, I just took a look at the task.

In the first part of the task, you just need to log the properties, so the following:

for (var something in shanghai){
   console.log(something);
}

In the second part, you need the properties and values.

for (var something in shanghai){
      console.log(something + ': ' + shanghai[something]);
}

Did you try them in this order? It is working for me.