* Fixed some translation errors. * Fixed some translation errors. * Fixed some translation errors. These errors will cause the code to be unable to run. * Fixed some translation errors. These errors will cause the code to be unable to run.
3.4 KiB
3.4 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7b8a367417b2b2512b4e | Create Strings using Template Literals | 1 | 使用模板文字创建字符串 |
Description
const person = {那里发生了很多事情。首先,例如使用反引号(
name: "Zodiac Hasbro",
age: 56
};
//具有多行和字符串插值的模板文字
const greeting =`您好,我的名字是${person.name}!
我是${person.age}岁。`
的console.log(greeting); //打印
//你好,我的名字是Zodiac Hasbro!
//我今年56岁
`
),而不是引号( '
或"
),换行字符串。其次,请注意,该字符串是多线,无论是在代码和输出。这节省了插入\n
串内。上面使用的${variable}
语法是占位符。基本上,您不必再使用+
运算符连接。要将变量添加到字符串,只需将变量放在模板字符串中并用${
包装它}
同样,您可以在您的字符串表达式的其他文字,例如${a + b}
这个新创建的字符串的方式为您提供了更大的灵活性,以创建强大的字符串。 Instructions
result
对象的failure
数组的每个条目。每个条目都应该包含在一个带有class属性text-warning
的li
元素中,并列在resultDisplayArray
。 Tests
tests:
- text: <code>resultDisplayArray</code>是一个包含<code>result failure</code>消息的数组。
testString: 'assert(typeof makeList(result.failure) === "object" && resultDisplayArray.length === 3, "<code>resultDisplayArray</code> is a list containing <code>result failure</code> messages.");'
- text: <code>resultDisplayArray</code>是所需的输出。
testString: 'assert(makeList(result.failure).every((v, i) => v === `<li class="text-warning">${result.failure[i]}</li>` || v === `<li class="text-warning">${result.failure[i]}</li>`), "<code>resultDisplayArray</code> is the desired output.");'
- text: 使用了模板字符串
testString: 'getUserInput => assert(getUserInput("index").match(/`.*`/g), "Template strings were not used");'
Challenge Seed
const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
"use strict";
// change code below this line
const resultDisplayArray = null;
// change code above this line
return resultDisplayArray;
}
/**
* makeList(result.failure) should return:
* [ `<li class="text-warning">no-var</li>`,
* `<li class="text-warning">var-on-top</li>`,
* `<li class="text-warning">linebreak</li>` ]
**/
const resultDisplayArray = makeList(result.failure);
Solution
// solution required