JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Accessing All of the Properties in an Object

Ali Abbas
Ali Abbas
8,772 Points

My solution code is not working. Why?

challenge task 1 of 2

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

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

1 Answer

Steven Parker
Steven Parker
201,975 Points

You should have gotten this message: "Bummer: There was an error with your code: ReferenceError: Strict mode forbids implicit creation of global property 'key'":

for (let key in shanghai) {    // explicitly declare with "let" or "var"
Ali Abbas
Ali Abbas
8,772 Points

Perfect. Thanks for your reply.