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

Lester Rodrigo
PLUS
Lester Rodrigo
Courses Plus Student 9,549 Points

JavaScript Objects For in Loop Problem please help I'm typing the right code I dont know what's wrong

Now that you are logging out the property names, include the property values too. In other words you want to log out 4 lines that include both the property name and value. For example: "population: 14.35e6"

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

for ( var prop in shanghai ) { console.log(prop, ', ' shanghai[prop]); }

3 Answers

Steven Parker
Steven Parker
230,248 Points

You forgot to provide a link to the challenge, but based on the text, I'd guess you only need to combine your strings via concatenation (using +), and separate them with a colon (instead of a comma) and space, something like this:

for ( var prop in shanghai ) {
    console.log(prop + ': ' + shanghai[prop]);
}
Alec Plummer
Alec Plummer
15,181 Points

You are really close. Whenever you run into an issue, double/triple check your syntax for errors.

for (var prop in shanghai) {
  console.log(prop, ', ' + shanghai[prop]); // don't forget to concatenate! (', ' + shanghai[prop])
}
Lester Rodrigo
PLUS
Lester Rodrigo
Courses Plus Student 9,549 Points

hey thanks guys i got it. because on the example there's no concatination needed for that code

Steven Parker
Steven Parker
230,248 Points

But it would be the conventional way to do it.