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

for (prop in shanghai) { console.log(prop, ': ', shanghai.prop); }

Unsure what I am doing wrong. Can anyone help? Thanks

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

3 Answers

Hi Sandy,

You've accidentally placed your for loop inside the shanghai object creating a syntax error and you're also missing a closing curly brace.

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

// place your for in loop here after the closing of the shanghai object

Also, you'll get a message suggesting it's a good idea to use the var keyword for your prop variable.

Example: for (var prop in shanghai) {

I don't know about you but I have had to restudy core concepts in JavaScript. YouTube provides many JavaScript videos

for Functions, Closures, Variables and the like. Having another teacher's perspective has been invaluable for me,

Struggling as I am. (Hope this helps)

Jeremy Franklin

Julian Gutierrez
Julian Gutierrez
19,201 Points

For the second part of the challenge use bracket notation.