Accessing Nested Objects before the Holiday

Tell us what’s happening:

I am outputting the correct answer “maps”. however the dot/bracket notation is not accurate. I have looked at the example and can not see the mistake I have made. Any ideas?

Your code so far

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

// Only change code below this line

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/accessing-nested-objects

What do you mean by the dot/bracket notation is not accurate? You’re saying you’re getting the correct answer but not passing the test?

You should not have changed the property "glove box" to "glove_box". Change only the line that says “Change this line”.

yes thats correct . Iam not passing the Dot/Bracket notation part.
I do get the correct output though.
any idea why?

Did you try changing the code above the line back to what it was originally like @ArielLeslie suggested?

not sure why it works this way. But correct output happens when I add _ to glove box, at the top, as well as bottom. Otherwise it does not work.

The second problem is: var gloveBoxContents = myStorage.car[“inside”].glove_box;
This should be correct as I see it. If you see something worth changing let me know. Maybe its a bug.

var myStorage = {
“car”: {
“inside”: {
“glove_box”: “maps”,
“passenger seat”: “crumbs”
},
“outside”: {
“trunk”: “jack”
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.car[“inside”].glove_box;

image

The directions say to access glove box not glove_box

image

These directions specifically tell you not to change above the line. If I had to guess why you aren’t passing the challenge it’s because you didn’t follow the directions. You get the right answer because you are accessing glove_box which now exist because you have changed the initial object you were given.

As you can see your code gets a warning. If you check the warning it’s the biggest clue as to what you’re missing from this challenge.

The point of bracket notation is that it is there to use when you need to reference a variable [myVar] (notice no quotes), or when you need to reference a property that has a blank space in the name such as ['glove box'], notice the quotes that time.

As the warning says it doesn’t really make sense to put inside within brackets, So you get the answer you want because your code is valid JavaScript however you don’t follow the directions about not changing what you aren’t supposed to change.

I would suggest trying to solve it before looking at this but it’s supposed to be implemented like this:

Hey Thanks so much for the explanation. Made the changes and passed.

1 Like

Anytime good luck with the rest of your journey!