freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.russian.md

2.7 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, localeTitle
id title challengeType videoUrl forumTopicId localeTitle
56533eb9ac21ba0edf2244b8 Concatenating Strings with the Plus Equals Operator 1 https://scrimba.com/c/cbQmmC4 16803 Объединение строк с помощью оператора Plus Equals

Description

Мы также можем использовать оператор += для конкатенации строки в конец существующей строковой переменной. Это может быть очень полезно для разбиения длинной строки на несколько строк. Заметка
Следите за пробелами. Конкатенация не добавляет пробелов между конкатенированными строками, поэтому вам нужно будет добавить их самостоятельно.

Instructions

Постройте myStr в нескольких строках, myStr эти две строки: "This is the first sentence. " и "This is the second sentence." используя оператор += . Используйте оператор += аналогичный тому, как он отображается в редакторе. Начните с назначения первой строки myStr , затем добавьте вторую строку.

Tests

tests:
  - text: <code>myStr</code> should have a value of <code>This is the first sentence. This is the second sentence.</code>
    testString: assert(myStr === "This is the first sentence. This is the second sentence.");
  - text: Use the <code>+=</code> operator to build <code>myStr</code>
    testString: assert(code.match(/\w\s*\+=\s*["']/g).length > 1 && code.match(/\w\s*\=\s*["']/g).length > 1);

Challenge Seed

// Example
var ourStr = "I come first. ";
ourStr += "I come second.";

// Only change code below this line

var myStr;

After Tests

(function(){
  if(typeof myStr === 'string') {
    return 'myStr = "' + myStr + '"';
  } else {
    return 'myStr is not a string';
  }
})();

Solution

var ourStr = "I come first. ";
ourStr += "I come second.";

var myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";