2.4 KiB
2.4 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244c7 | ドット記法によるオブジェクトのプロパティへのアクセス | 1 | https://scrimba.com/c/cGryJs8 | 16164 | accessing-object-properties-with-dot-notation |
--description--
配列の場合と同様に、オブジェクトのプロパティへのアクセス方法も、ドット記法 (.
) とブラケット記法 ([]
) の 2 通りがあります。
ドット記法は、アクセスしようとしているプロパティの名前があらかじめわかっている場合に使用します。
次は、ドット記法 (.
) を使用してオブジェクトのプロパティを読み取る例です。
const myObj = {
prop1: "val1",
prop2: "val2"
};
const prop1val = myObj.prop1;
const prop2val = myObj.prop2;
prop1val
の値は文字列 val1
、prop2val
の値は文字列 val2
となります。
--instructions--
ドット記法を使用して testObj
のプロパティ値を取得してください。 変数 hatValue
はオブジェクトのプロパティ hat
と等しくなるように設定し、変数 shirtValue
はオブジェクトのプロパティ shirt
と等しくなるように設定してください。
--hints--
hatValue
は文字列である必要があります。
assert(typeof hatValue === 'string');
hatValue
の値は文字列 ballcap
である必要があります。
assert(hatValue === 'ballcap');
shirtValue
は文字列である必要があります。
assert(typeof shirtValue === 'string');
shirtValue
の値は文字列 jersey
である必要があります。
assert(shirtValue === 'jersey');
ドット記法を 2 回使用する必要があります。
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
const testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
const hatValue = testObj; // Change this line
const shirtValue = testObj; // Change this line
--solutions--
const testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
const hatValue = testObj.hat;
const shirtValue = testObj.shirt;