2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244b7
title: Concatenating Strings with Plus Operator
challengeType: 1
videoUrl: ''
localeTitle: 用Plus运算符连接字符串
---
## Description
< section id = "description" > 在JavaScript中, 当< code > +</ code > 运算符与< code > String</ code > 值一起使用时,它被称为< dfn > 连接</ dfn > 运算符。您可以通过< dfn > 将</ dfn > 它们< dfn > 连接</ dfn > 在一起来构建其他字符串中的新字符串。 < strong > 例</ strong > < blockquote > “我叫艾伦,& #39 ; +& #39 ; 我连接起来。” </ blockquote > < strong > 注意</ strong > < br > 留意空间。连接不会在连接字符串之间添加空格,因此您需要自己添加它们。 </ section >
## Instructions
< section id = "instructions" > 从字符串构建< code > myStr< / code > < code > " This is the start. " < / code > 和< code > " This is the end." < / code > 使用< code > +< / code > 运算符。 < / section >
## Tests
< section id = 'tests' >
```yml
tests:
- text: < code > myStr</ code > 应该有一个值< code > This is the start. This is the end.</ code >
2020-02-18 01:40:55 +09:00
testString: assert(myStr === "This is the start. This is the end.");
2018-10-10 18:03:03 -04:00
- text: 使用< code > +</ code > 运算符构建< code > myStr</ code >
2020-02-18 01:40:55 +09:00
testString: assert(code.match(/(["']).*(["'])\s*\+\s*(["']).*(["'])/g).length > 1);
2018-10-10 18:03:03 -04:00
- text: 应使用< code > var</ code > 关键字创建< code > myStr</ code > 。
2020-02-18 01:40:55 +09:00
testString: assert(/var\s+myStr/.test(code));
2018-10-10 18:03:03 -04:00
- text: 确保将结果分配给< code > myStr</ code > 变量。
2020-02-18 01:40:55 +09:00
testString: assert(/myStr\s*=/.test(code));
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Example
var ourStr = "I come first. " + "I come second.";
// Only change code below this line
var myStr;
```
< / div >
### After Test
< div id = 'js-teardown' >
```js
console.info('after the test');
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
// solution required
```
< / section >