--- id: 56533eb9ac21ba0edf2244b8 title: Concatenating Strings with the Plus Equals Operator challengeType: 1 videoUrl: https://scrimba.com/c/cbQmmC4 forumTopicId: 16803 localeTitle: Объединение строк с помощью оператора Plus Equals --- ## Description
Мы также можем использовать оператор += для конкатенации строки в конец существующей строковой переменной. Это может быть очень полезно для разбиения длинной строки на несколько строк. Заметка
Следите за пробелами. Конкатенация не добавляет пробелов между конкатенированными строками, поэтому вам нужно будет добавить их самостоятельно.
## Instructions
Постройте myStr в нескольких строках, myStr эти две строки: "This is the first sentence. " и "This is the second sentence." используя оператор += . Используйте оператор += аналогичный тому, как он отображается в редакторе. Начните с назначения первой строки myStr , затем добавьте вторую строку.
## Tests
```yml tests: - text: myStr should have a value of This is the first sentence. This is the second sentence. testString: assert(myStr === "This is the first sentence. This is the second sentence."); - text: Use the += operator to build myStr testString: assert(code.match(/\w\s*\+=\s*["']/g).length > 1 && code.match(/\w\s*\=\s*["']/g).length > 1); ```
## Challenge Seed
```js // Example var ourStr = "I come first. "; ourStr += "I come second."; // Only change code below this line var myStr; ```
### After Tests
```js (function(){ if(typeof myStr === 'string') { return 'myStr = "' + myStr + '"'; } else { return 'myStr is not a string'; } })(); ```
## Solution
```js var ourStr = "I come first. "; ourStr += "I come second."; var myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ```