freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../basic-javascript/concatenating-strings-with-...

1.8 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244b8 Concatenar strings com o operador mais igual 1 https://scrimba.com/c/cbQmmC4 16803 concatenating-strings-with-the-plus-equals-operator

--description--

Também podemos usar o operador += para concatenar uma string no final de uma variável string existente. Isso pode ser muito útil para quebrar uma longa string em várias linhas.

Observação: cuidado com os espaços. A concatenação não adiciona espaços entre strings concatenadas, então você mesmo precisará adicioná-los.

Exemplo:

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

ourStr agora deve ter como valor a string I come first. I come second..

--instructions--

Crie myStr em várias linhas concatenando essas duas strings: This is the first sentence. e This is the second sentence. usando o operador +=. Use o operador += de modo semelhante a como ele é mostrado no exemplo e certifique-se de incluir um espaço entre as duas strings. Comece atribuindo o primeiro texto para myStr, e então adicione o segundo texto.

--hints--

myStr deve ter como valor a string This is the first sentence. This is the second sentence.

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

Você deve usar o operador += para criar 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.";