2018-10-10 22:03:03 +00:00
---
id: 56533eb9ac21ba0edf2244b7
title: Concatenating Strings with Plus Operator
challengeType: 1
2019-08-28 13:26:13 +00:00
videoUrl: https://scrimba.com/c/cNpM8AN
forumTopicId: 16802
2018-10-10 22:03:03 +00:00
localeTitle: Конкатенация строк с помощью оператора Plus
---
## Description
2019-08-28 13:26:13 +00:00
< section id = 'description' >
В JavaScript, когда оператор < code > +< / code > используется с о значением < code > String< / code > , он называется оператором < dfn > конкатенации< / dfn > . Вы можете создать новую строку из других строк путем < dfn > конкатенации< / dfn > их вместе. < strong > пример< / strong > < blockquote > «Меня зовут Алан, +, я конкатенирую». < / blockquote > < strong > Заметка< / strong > < br > Следите за пробелами. Конкатенация не добавляет пробелов между конкатенированными строками, поэтому вам нужно будет добавить их самостоятельно.
< / section >
2018-10-10 22:03:03 +00:00
## Instructions
2019-08-28 13:26:13 +00:00
< section id = 'instructions' >
Создайте < code > myStr< / code > из строк < code > " This is the start. " < / code > и < code > " This is the end." < / code > используя оператор < code > +< / code > .
< / section >
2018-10-10 22:03:03 +00:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 13:26:13 +00:00
- text: < code > myStr</ code > should have a value of < code > This is the start. This is the end.</ code >
testString: assert(myStr === "This is the start. This is the end.");
- text: Use the < code > +</ code > operator to build < code > myStr</ code >
testString: assert(code.match(/(["']).*(["'])\s*\+\s*(["']).*(["'])/g).length > 1);
- text: < code > myStr</ code > should be created using the < code > var</ code > keyword.
testString: assert(/var\s+myStr/.test(code));
- text: Make sure to assign the result to the < code > myStr</ code > variable.
testString: assert(/myStr\s*=/.test(code));
2018-10-10 22:03:03 +00: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 >
2019-08-28 13:26:13 +00:00
### After Tests
2018-10-10 22:03:03 +00:00
< div id = 'js-teardown' >
```js
2019-08-28 13:26:13 +00:00
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
2018-10-10 22:03:03 +00:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 13:26:13 +00:00
var ourStr = "I come first. " + "I come second.";
var myStr = "This is the start. " + "This is the end.";
2018-10-10 22:03:03 +00:00
```
2019-08-28 13:26:13 +00:00
2018-10-10 22:03:03 +00:00
< / section >