* 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
3.4 KiB
3.4 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56bbb991ad1ed5201cd392d0 | Build JavaScript Objects | 1 | 构建JavaScript对象 |
Description
object
这个术语。对象类似于arrays
,除了不使用索引访问和修改数据,您可以通过所谓的properties
访问对象中的数据。对象对于以结构化方式存储数据很有用,并且可以表示真实世界对象,如猫。这是一个示例cat对象: var cat = {在此示例中,所有属性都存储为字符串,例如 -
“名字”:“胡须”,
“腿”:4,
“尾巴”:1,
“敌人”:[“水”,“狗”]
};
"name"
, "legs"
和"tails"
。但是,您也可以使用数字作为属性。您甚至可以省略单字符串属性的引号,如下所示: var anotherObject = {但是,如果您的对象具有任何非字符串属性,JavaScript将自动将它们作为字符串进行类型转换。
制作:“福特”,
5:“五”,
“模特”:“焦点”
};
Instructions
myDog
的狗的对象,其中包含属性"name"
(字符串), "legs"
, "tails"
和"friends"
。您可以将这些对象属性设置为您想要的任何值,因为"name"
是一个字符串, "legs"
和"tails"
是数字, "friends"
是一个数组。 Tests
tests:
- text: <code>myDog</code>应该包含属性<code>name</code> ,它应该是一个<code>string</code> 。
testString: assert((function(z){if(z.hasOwnProperty("name") && z.name !== undefined && typeof z.name === "string"){return true;}else{return false;}})(myDog));
- text: <code>myDog</code>应该包含属性<code>legs</code> ,它应该是一个<code>number</code> 。
testString: assert((function(z){if(z.hasOwnProperty("legs") && z.legs !== undefined && typeof z.legs === "number"){return true;}else{return false;}})(myDog));
- text: <code>myDog</code>应该包含属性<code>tails</code> ,它应该是一个<code>number</code> 。
testString: assert((function(z){if(z.hasOwnProperty("tails") && z.tails !== undefined && typeof z.tails === "number"){return true;}else{return false;}})(myDog));
- text: <code>myDog</code>应该包含属性<code>friends</code> ,它应该是一个<code>array</code> 。
testString: assert((function(z){if(z.hasOwnProperty("friends") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog));
- text: <code>myDog</code>应该只包含所有给定的属性。
testString: assert((function(z){return Object.keys(z).length === 4;})(myDog));
Challenge Seed
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
// Only change code below this line.
var myDog = {
};
After Test
console.info('after the test');
Solution
// solution required