mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-09 06:04:17 -05:00
2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244cc | Доступ до вкладених об'єктів | 1 | https://scrimba.com/c/cRnRnfa | 16161 | accessing-nested-objects |
--description--
Доступ до підвластивостей об'єктів можна отримати завдяки ланцюжку точкової та дужкової нотацій.
Ось вкладений об'єкт:
const ourStorage = {
"desk": {
"drawer": "stapler"
},
"cabinet": {
"top drawer": {
"folder1": "a file",
"folder2": "secrets"
},
"bottom drawer": "soda"
}
};
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
ourStorage.cabinet["top drawer"].folder2 буде рядком secrets, а ourStorage.desk.drawer буде рядком stapler.
--instructions--
Отримайте доступ до myStorage та призначте вміст властивості glove box до змінної gloveBoxContents. Використайте точкову нотацію для всіх властивостей, де можливо. В іншому випадку використайте дужкову нотацію.
--hints--
gloveBoxContents повинен дорівнювати рядку maps.
assert(gloveBoxContents === 'maps');
Щоб отримати доступ до myStorage, використайте точкову та дужкову нотацію.
assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
--seed--
--after-user-code--
(function(x) {
if(typeof x != 'undefined') {
return "gloveBoxContents = " + x;
}
return "gloveBoxContents is undefined";
})(gloveBoxContents);
--seed-contents--
const myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
const gloveBoxContents = undefined;
--solutions--
const myStorage = {
"car":{
"inside":{
"glove box":"maps",
"passenger seat":"crumbs"
},
"outside":{
"trunk":"jack"
}
}
};
const gloveBoxContents = myStorage.car.inside["glove box"];