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

Rod R
Rod R
3,050 Points

quiz auto error

having trouble with a quiz for JS loops arrays and objects- error message is "bummer: its a good idea to use a var keyword such as 'var key in shanghai' <<< the problem is thats what I am doing and have in in the workspace. Ive tried to reset and try again but the same error appears.

var shanghai = { population: 14, longitude: 31, country: 'CHN' };

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

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

again, error suggests that I use var keyword (??) and Im unable to clear it by resetting the exercise

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

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

for (var key in shanghai) {
  console.log(key, ': ', shanghai[key]); 
}; 
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Steven Parker
Steven Parker
231,275 Points

I think the issue is that you have two separate loops. This is one of the few challenges where you are asked to modify the code you created for the first task instead of creating completely new code for the second task.

Rod R
Rod R
3,050 Points

Great. Then I have some suggestions about this workspace to improve the experience for learners like me.

Steven Parker
Steven Parker
231,275 Points

You can always send suggestions to the staff as described on the Support page.

If your question is resolved, you can mark it solved by choosing a "best answer".

Happy Holidays! :christmas_tree: And for fun and coding practice, give Advent of Code a try. :santa: