* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
1.8 KiB
1.8 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dad367417b2b2512b75 | Create a Method on an Object | 1 | 在对象上创建方法 |
Description
Objects
可以具有特殊类型的property
,称为method
。 Methods
是作为函数的properties
。这会为object
添加不同的行为。这是一个方法的duck
示例: 让duck = {该示例添加了
名称:“Aflac”,
numLegs:2,
sayName:function(){return“这个鸭子的名字是”+ duck.name +“。”;}
};
duck.sayName();
//返回“这个鸭子的名字是Aflac。”
sayName
method
,该method
是一个返回给出duck
名称的句子的函数。请注意,该method
使用duck.name
访问return语句中的name
属性。下一个挑战将包括另一种方法。 Instructions
dog
object
,给它一个名为sayLegs
的方法。该方法应该返回句子“这条狗有4条腿”。 Tests
tests:
- text: <code>dog.sayLegs()</code>应该是一个函数。
testString: assert(typeof(dog.sayLegs) === 'function');
- text: <code>dog.sayLegs()</code>应返回给定的字符串 - 请注意标点符号和间距很重要。
testString: assert(dog.sayLegs() === 'This dog has 4 legs.');
Challenge Seed
let dog = {
name: "Spot",
numLegs: 4,
};
dog.sayLegs();
Solution
// solution required