Accessing Nested Objects 2019

Tell us what’s happening:

I just copied the hint because I don’t understand the question and, don’t know how to do this problem.

Your code so far


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

var gloveBoxContents = myStorage.car.inside.[glovebox]; //"maps" // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects/

The question is that you have to pick the value in the “glove box”.

Imagine you have a storage room called as “myStorage”. This room has a big container called as “car”. In that “car” there are two big boxes “inside” and “outside”. In the “inside” box there are two more boxes “glove box” and “passenger seat”. You have to pick what is inside “glove box”

So you go step by step.

This is the code that leads to the value you are looking for:
mStorage.car.inside["glove box"]

Note:

The reason why I used myStorage.car.inside["glove box"]
instead of myStorage.car.inside.glove box is that “glove box” has a space in it. And dot notation would not work in such case so we must use bracket notation.

I put that exact answer you gave me and it didn’t work.

That is because I did not gave the exact answer.

I tried to provide the explanation, so that you can come up with an answer yourself. :slight_smile:

I had the right answer from the start but, I forgot to put the space between glove and box. I just assumed it was one word. So it was a minor error. Thanks for the explanation it made me understand the problem.

1 Like