* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.9 KiB
1.9 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244c7 | Accessing Object Properties with Dot Notation | 1 | https://scrimba.com/c/cGryJs8 | 16164 | accessing-object-properties-with-dot-notation |
--description--
There are two ways to access the properties of an object: dot notation (.
) and bracket notation ([]
), similar to an array.
Dot notation is what you use when you know the name of the property you're trying to access ahead of time.
Here is a sample of using dot notation (.
) to read an object's property:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
--instructions--
Read in the property values of testObj
using dot notation. Set the variable hatValue
equal to the object's property hat
and set the variable shirtValue
equal to the object's property shirt
.
--hints--
hatValue
should be a string
assert(typeof hatValue === 'string');
The value of hatValue
should be "ballcap"
assert(hatValue === 'ballcap');
shirtValue
should be a string
assert(typeof shirtValue === 'string');
The value of shirtValue
should be "jersey"
assert(shirtValue === 'jersey');
You should use dot notation twice
assert(code.match(/testObj\.\w+/g).length > 1);
--seed--
--after-user-code--
(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
--seed-contents--
// Setup
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj; // Change this line
var shirtValue = testObj; // Change this line
--solutions--
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;