2.5 KiB
2.5 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244cc | Accessing Nested Objects | 1 | https://scrimba.com/c/cRnRnfa | 16161 | Доступ к вложенным объектам |
Description
var ourStorage = {
"стол письменный": {
«ящик»: «степлер»
},
«кабинет»: {
"верхний ящик": {
«folder1»: «файл»,
"folder2": "секреты"
},
«нижний ящик»: «сода»
}
};
ourStorage.cabinet ["верхний ящик"]. folder2; // "секреты"
ourStorage.desk.drawer; // "степлер"
Instructions
myStorage
и назначьте содержимое свойства glove box
переменной gloveBoxContents
. Используйте обозначения в виде скобок для свойств с пробелом в их имени.
Tests
tests:
- text: <code>gloveBoxContents</code> should equal "maps"
testString: assert(gloveBoxContents === "maps");
- text: Use dot and bracket notation to access <code>myStorage</code>
testString: assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
Challenge Seed
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
var gloveBoxContents = undefined; // Change this line
After Tests
(function(x) {
if(typeof x != 'undefined') {
return "gloveBoxContents = " + x;
}
return "gloveBoxContents is undefined";
})(gloveBoxContents);
Solution
var myStorage = {
"car":{
"inside":{
"glove box":"maps",
"passenger seat":"crumbs"
},
"outside":{
"trunk":"jack"
}
}
};
var gloveBoxContents = myStorage.car.inside["glove box"];