2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244c7 | Accessing Object Properties with Dot Notation | 1 | 使用点表示法访问对象属性 |
Description
.
)和括号表示法( []
),类似于数组。当您知道要提前访问的属性的名称时,使用点符号。以下是使用点表示法( .
)读取对象属性的示例: var myObj = {
prop1:“val1”,
prop2:“val2”
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
Instructions
testObj
的属性值。将变量hatValue
设置为等于对象的属性hat
,并将变量shirtValue
设置为等于对象的属性shirt
。 Tests
tests:
- text: <code>hatValue</code>应该是一个字符串
testString: 'assert(typeof hatValue === "string" , "<code>hatValue</code> should be a string");'
- text: <code>hatValue</code>的值应该是<code>"ballcap"</code>
testString: 'assert(hatValue === "ballcap" , "The value of <code>hatValue</code> should be <code>"ballcap"</code>");'
- text: <code>shirtValue</code>应该是一个字符串
testString: 'assert(typeof shirtValue === "string" , "<code>shirtValue</code> should be a string");'
- text: <code>shirtValue</code>的值应该是<code>"jersey"</code>
testString: 'assert(shirtValue === "jersey" , "The value of <code>shirtValue</code> should be <code>"jersey"</code>");'
- text: 你应该使用点符号两次
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
Challenge Seed
// 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
After Test
console.info('after the test');
Solution
// solution required