2021-06-15 00:49:18 -07:00
---
id: 56533eb9ac21ba0edf2244ed
2021-07-21 20:53:20 +05:30
title: Adicionar variáveis para strings
2021-06-15 00:49:18 -07:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cbQmZfa'
forumTopicId: 16656
dashedName: appending-variables-to-strings
---
# --description--
2021-07-09 21:23:54 -07:00
Assim como podemos construir uma string em várias linhas através das strings < dfn > literais</ dfn > , nós também podemos adicionar as variáveis para a string usando o operador mais igual (`+=` ).
2021-06-15 00:49:18 -07:00
2021-07-09 21:23:54 -07:00
Exemplo:
2021-06-15 00:49:18 -07:00
```js
2021-10-27 15:10:57 +00:00
const anAdjective = "awesome!";
let ourStr = "freeCodeCamp is ";
2021-06-15 00:49:18 -07:00
ourStr += anAdjective;
```
2021-07-09 21:23:54 -07:00
`ourStr` teria o valor `freeCodeCamp is awesome!` .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-09 21:23:54 -07:00
Defina `someAdjective` para uma string de pelo menos 3 caracteres e adicione para `myStr` usando o operador `+=` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-09 21:23:54 -07:00
`someAdjective` deve ser definida para uma string de pelo menos o tamanho de 3 caracteres.
2021-06-15 00:49:18 -07:00
```js
assert(typeof someAdjective !== 'undefined' & & someAdjective.length > 2);
```
2021-07-09 21:23:54 -07:00
Você deve adicionar `someAdjective` para `myStr` usando o operador `+=` .
2021-06-15 00:49:18 -07:00
```js
assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
```
# --seed--
## --after-user-code--
```js
(function(){
var output = [];
if(typeof someAdjective === 'string') {
output.push('someAdjective = "' + someAdjective + '"');
} else {
output.push('someAdjective is not a string');
}
if(typeof myStr === 'string') {
output.push('myStr = "' + myStr + '"');
} else {
output.push('myStr is not a string');
}
return output.join('\n');
})();
```
## --seed-contents--
```js
// Change code below this line
2021-10-27 15:10:57 +00:00
const someAdjective = "";
let myStr = "Learning to code is ";
2021-06-15 00:49:18 -07:00
```
# --solutions--
```js
2021-10-27 15:10:57 +00:00
const someAdjective = "neat";
let myStr = "Learning to code is ";
2021-06-15 00:49:18 -07:00
myStr += someAdjective;
```