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

2.3 KiB
Raw Permalink Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244b8 Об'єднання рядків за допомогою оператора "плюс дорівнює" 1 https://scrimba.com/c/cbQmmC4 16803 concatenating-strings-with-the-plus-equals-operator

--description--

Ми можемо також використовувати оператор +=, щоб з'єднувати рядок з кінцем уже існуючого рядка змінної. Або ще для того, щоб розділяти довгий рядок над кількома рядками.

Примітка: Зверніть увагу на пробіли. Під час об'єднання між рядками відсутні пробіли, вам потрібно буде додати їх самостійно.

Наприклад:

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

ourStr зараз має значення рядка I come first. I come second..

--instructions--

Введіть myStr над кількома рядками, об'єднуючи ці два рядки: This is the first sentence. і This is the second sentence.. Використовуйте оператор +=. Використовуйте += оператор, подібний до того, як показно в прикладі, й обов'язково зверніть увагу на наявність пробіл між рядками. Почніть з призначення першого рядка myStr, а потім додайте до другого рядка.

--hints--

myStr повинен мати значення рядка This is the first sentence. This is the second sentence.

assert(myStr === 'This is the first sentence. This is the second sentence.');

Для створення myStr потрібно використовувати +=.

assert(code.match(/myStr\s*\+=\s*(["']).*\1/g));

--seed--

--after-user-code--

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

--seed-contents--

let myStr;

--solutions--

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