Access Nested Objects Tests, are They Correct?

I used the following code:

// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

var gloveBoxContents = myStorage.car["inside"]["glove box"]; // Change this line
console.log(gloveBoxContents);

It doesn’t pass, because it says that it doesn’t use dot and bracket notation. However, it seems to use dot and bracket notation.

This does pass:

// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

var gloveBoxContents = myStorage.car.inside["glove box"]; // Change this line
console.log(gloveBoxContents);

I don’t know what to conclude other than the tests aren’t correct.

Your code does the same thing, but the test is expecting that inside is accessed with dot notation. In general, if you can access a property with dot notation (like inside), use dot notation, because it looks cleaner

1 Like