mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-31 15:03:21 -05:00
* fix(curriculum): test that assignment is unchanged * chore: apply gikf's review Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com> --------- Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com>
2.0 KiB
2.0 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244cc | Accessing Nested Objects | 1 | https://scrimba.com/c/cRnRnfa | 16161 | accessing-nested-objects |
--description--
The sub-properties of objects can be accessed by chaining together the dot or bracket notation.
Here is a nested object:
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 would be the string secrets, and ourStorage.desk.drawer would be the string stapler.
--instructions--
Access the myStorage object and assign the contents of the glove box property to the gloveBoxContents variable. Use dot notation for all properties where possible, otherwise use bracket notation.
--hints--
gloveBoxContents should equal the string maps.
assert(gloveBoxContents === 'maps');
Your code should use dot and bracket notation to access myStorage.
assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
gloveBoxContents should still be declared with const.
assert.match(code, /const\s+gloveBoxContents\s*=/)
--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"];