freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../object-oriented-programming/use-dot-notation-to-access-...

1.8 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7dac367417b2b2512b74 Use Dot Notation to Access the Properties of an Object 1 使用点表示法访问对象的属性

Description

最后一个挑战创建了一个具有各种propertiesobject ,现在您将看到如何访问这些properties的值。这是一个例子:
让duck = {
名称“Aflac”
numLegs2
};
的console.logduck.name;
//这会将“Aflac”打印到控制台
点符号用于object名称duck ,后跟property name 以访问“Aflac”的值。

Instructions

将以下dog对象的两个properties打印到控制台。

Tests

tests:
  - text: 您应该使用<code>console.log</code>来打印<code>dog</code>对象的<code>name</code>属性的值。
    testString: 'assert(/console.log\(.*dog\.name.*\)/g.test(code), "Your should use <code>console.log</code> to print the value for the <code>name</code> property of the <code>dog</code> object.");'
  - text: 您应该使用<code>console.log</code>来打印<code>dog</code>对象的<code>numLegs</code>属性的值。
    testString: 'assert(/console.log\(.*dog\.numLegs.*\)/g.test(code), "Your should use <code>console.log</code> to print the value for the <code>numLegs</code> property of the <code>dog</code> object.");'

Challenge Seed

let dog = {
  name: "Spot",
  numLegs: 4
};
// Add your code below this line

Solution

// solution required