1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244b7 | 用加号运算符连接字符串 | 1 | https://scrimba.com/c/cNpM8AN | 16802 | concatenating-strings-with-plus-operator |
--description--
在 JavaScript 中,当 +
操作符被用于一个 String
类型的值的时候,它被称作拼接操作符。 你可以通过拼接其他字符串来创建一个新的字符串。
例如:
'My name is Alan,' + ' I concatenate.'
提示: 注意空格。 拼接操作不会在两个字符串之间添加空格。所以,如果想加上空格的话,你需要自己在字符串里面添加。
例如:
const ourStr = "I come first. " + "I come second.";
字符串 I come first. I come second.
将显示在控制台中。
--instructions--
用字符串 This is the start.
和 This is the end.
通过 +
运算符创建 myStr
。 确保在两个字符串之间包含一个空格。
--hints--
myStr
的值应该是 This is the start. This is the end.
assert(myStr === 'This is the start. This is the end.');
应使用 +
操作符创建 myStr
。
assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
myStr
应该使用 const
关键字创建。
assert(/const\s+myStr/.test(code));
应把结果赋值给 myStr
变量。
assert(/myStr\s*=/.test(code));
--seed--
--after-user-code--
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
--seed-contents--
const myStr = ""; // Change this line
--solutions--
const myStr = "This is the start. " + "This is the end.";