Files

69 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

---
id: 56533eb9ac21ba0edf2244b8
title: Concatenar strings com o operador mais igual
challengeType: 1
videoUrl: 'https://scrimba.com/c/cbQmmC4'
forumTopicId: 16803
dashedName: concatenating-strings-with-the-plus-equals-operator
---
# --description--
2021-07-09 21:23:54 -07:00
Também podemos usar o operador `+=` para <dfn>concatenar</dfn> 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.
2021-07-09 21:23:54 -07:00
Exemplo:
```js
let ourStr = "I come first. ";
ourStr += "I come second.";
```
2021-07-09 21:23:54 -07:00
`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--
2021-07-09 21:23:54 -07:00
`myStr` deve ter como valor a string `This is the first sentence. This is the second sentence.`
```js
assert(myStr === 'This is the first sentence. This is the second sentence.');
```
Você deve usar o operador `+=` para criar `myStr`.
```js
assert(code.match(/myStr\s*\+=\s*(["']).*\1/g));
```
# --seed--
## --after-user-code--
```js
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
```
## --seed-contents--
```js
let myStr;
```
# --solutions--
```js
let myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";
```