Accessing Nested Objects before the Holiday

Accessing Nested Objects before the Holiday
0.0 0

#1

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:


#2

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?


#3

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


#4

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


#5

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


#6

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;


#7

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:


#8

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


#9

Anytime good luck with the rest of your journey!