* 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
4.0 KiB
4.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244cb | Manipulating Complex Objects | 1 | 操纵复杂对象 |
Description
var ourMusic = [这是一个包含一个对象的数组。该对象具有关于专辑的各种元数据 。它还有一个嵌套的
{
“艺术家”:“Daft Punk”,
“标题”:“家庭作业”,
“release_year”:1997年,
“格式”:[
“光盘”,
“盒式”
“LP”
]
“黄金”:是的
}
]。
"formats"
数组。如果要添加更多专辑记录,可以通过向顶级数组添加记录来完成此操作。对象将数据保存在属性中,该属性具有键值格式。在上面的示例中, "artist": "Daft Punk"
是具有"artist"
键和"Daft Punk"
值的属性。 JavaScript Object Notation或JSON
是用于存储数据的相关数据交换格式。 {注意
“艺术家”:“Daft Punk”,
“标题”:“家庭作业”,
“release_year”:1997年,
“格式”:[
“光盘”,
“盒式”
“LP”
]
“黄金”:是的
}
除非它是数组中的最后一个对象,否则您需要在数组中的每个对象后面放置一个逗号。
Instructions
myMusic
阵列。添加artist
和title
字符串, release_year
数字和formats
字符串数组。 Tests
tests:
- text: <code>myMusic</code>应该是一个数组
testString: assert(Array.isArray(myMusic));
- text: <code>myMusic</code>应该至少有两个元素
testString: assert(myMusic.length > 1);
- text: '<code>myMusic[1]</code>应该是一个对象'
testString: assert(typeof myMusic[1] === 'object');
- text: '<code>myMusic[1]</code>应该至少有4个属性'
testString: assert(Object.keys(myMusic[1]).length > 3);
- text: '<code>myMusic[1]</code>应该包含一个<code>artist</code>属性,它是一个字符串'
testString: assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string');
- text: '<code>myMusic[1]</code>应该包含一个<code>title</code>属性,它是一个字符串'
testString: assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string');
- text: '<code>myMusic[1]</code>应该包含一个<code>release_year</code>属性,它是一个数字'
testString: assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number');
- text: '<code>myMusic[1]</code>应该包含一个<code>formats</code>属性,它是一个数组'
testString: assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats));
- text: <code>formats</code>应该是一个至少包含两个元素的字符串数组
testString: assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1);
Challenge Seed
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CD",
"8T",
"LP"
],
"gold": true
}
// Add record here
];
After Test
console.info('after the test');
Solution
// solution required