* 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.3 KiB
1.3 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7dac367417b2b2512b74 | 使用点符号来访问对象的属性 | 1 | 301333 | use-dot-notation-to-access-the-properties-of-an-object |
--description--
在上一个挑战中,我们创建了一个拥有不同属性
的对象
,现在我们来看看该如何访问这些属性
:
let duck = {
name: "Aflac",
numLegs: 2
};
console.log(duck.name);
// 这段代码会在控制台中输出 "Aflac"
我们可以用“点号表示法”来访问对象的属性,只需要在对象
名称后面加上.
以及属性
名即可。比如,duck.name
就可以访问到 "Aflac"。
--instructions--
请在控制台里面输出dog
对象中两个属性
对应的值。
--hints--
你应该使用console.log
来将dog
对象的name
属性值输出到控制台。
assert(/console.log\(.*dog\.name.*\)/g.test(code));
你应该使用console.log
来将dog
对象的numLegs
属性值输出到控制台。
assert(/console.log\(.*dog\.numLegs.*\)/g.test(code));
--seed--
--seed-contents--
let dog = {
name: "Spot",
numLegs: 4
};
// Only change code below this line
--solutions--
let dog = {
name: "Spot",
numLegs: 4
};
console.log(dog.name);
console.log(dog.numLegs);