2.0 KiB
2.0 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244b7 | 1 | https://scrimba.com/c/cNpM8AN | 16802 | 用加号运算符连接字符串 |
Description
String
类型的值使用+
操作符的时候,它被称作 拼接操作符。你可以通过拼接其他字符串来创建一个新的字符串。
示例
'My name is Alan,' + ' I concatenate.'
提示
注意空格。拼接操作不会在两个字符串之间添加空格,所以想加上空格的话,你需要自己在字符串里面添加。
Instructions
+
操作符,把字符串"This is the start. "
和"This is the end."
连接起来并赋值给变量myStr
。
Tests
tests:
- text: <code>myStr</code>的值应该是<code>This is the start. This is the end.</code>。
testString: assert(myStr === "This is the start. This is the end.");
- text: 使用<code>+</code>操作符构建<code>myStr</code>。
testString: assert(code.match(/(["']).*(["'])\s*\+\s*(["']).*(["'])/g).length > 1);
- text: <code>myStr</code>应该被<code>var</code>关键字声明。
testString: assert(/var\s+myStr/.test(code));
- text: 确保有给<code>myStr</code>赋值。
testString: assert(/myStr\s*=/.test(code));
Challenge Seed
// Example
var ourStr = "I come first. " + "I come second.";
// Only change code below this line
var myStr;
After Test
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
Solution
var ourStr = "I come first. " + "I come second.";
var myStr = "This is the start. " + "This is the end.";