Hey guys, I am having trouble assigning object properties to a variable. The challenge that I am specifically working on is: Basic Java - Accessing Nested Objects.
I have been trying to assign the property (“glove box”) of the object (myStorage) to the new variable (gloveBoxContents) but, either I am getting [object.Object] or Undefined.
I know that code is read/assigned/declared from right to left, but I am struggling with this one and how to structure it. Any help would be greatly appreciated.
ourStorage (Object), “.” or dot notation < calls on the property cabinet and property [“top drawer”]. Top drawer is in bracket notation because there is a space between the words “Top_drawer”. folder 2 holds the value “secrets”.
It could be the " // Only change code below this lin " missing the “e” . The way you have accessed it looks correct. Would you try correcting that and see if you get the solution?
How would I bracket several words? For example, suppose instead of this:
var gloveBoxContents = myStorage.car.inside[“glove box”];
If “inside” was “inside car”
Can you do this:
var gloveBoxContents = myStorage.car[“inside car”][“glove box”];
I am just wondering - it seems like the bracket was useful here because glove box is 2 words, and so using the dot notation would not work. But, suppose if you have 2 phrases next to each other, how do you properly notate?
…
// Setup
var myStorage = {
“car”: {
“inside”: {
“glove box”: “maps”,
“passenger seat”: “crumbs”
},
“outside”: {
“trunk”: “jack”
}
}
};
var gloveBoxContents = myStorage.car.inside[“glove box”]; // Change this line
…
Hahaha I was doing similar and wondering why it wasn’t working. Read this thread and checked my code again. Had “glove box” capitalized “Glove box”. Changed Glove to glove and passed the tests finally!!! : )