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

now that you are logging out property names, include property values too

js loops,arrays, objects

1 Answer

Hey Nokuthula!

So it looks like you got past the first part of the challenge, so you should be somewhere around here:

var shanghai = {
  population: 14.35e6,
  longitude: '31.2000 N',
  latitude: '121.5000 E',
  country: 'CHN'
};

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

Which outputs "population", "longitude", "latitude", and "country" to the console. Now to access the values associated with each of those properties, you'll either need to use dot or bracket notation for each property. So for dot notation: shanghai.property, or for bracket notation: shanghai[property].

So if you wanted to output to the screen the property, followed by a colon, followed by a space, and finally followed by the property's value, you'd want to do something like this (shown in dot notation):

for(var property in shanghai){
 console.log(property + ": " + shanghai.property); 
}

Hope that helps!