2021-06-15 07:49:18 +00:00
---
id: 56533eb9ac21ba0edf2244ed
2021-07-21 15:23:20 +00:00
title: Adicionar variáveis para strings
2021-06-15 07:49:18 +00:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cbQmZfa'
forumTopicId: 16656
dashedName: appending-variables-to-strings
---
# --description--
2021-07-10 04:23:54 +00: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 07:49:18 +00:00
2021-07-10 04:23:54 +00:00
Exemplo:
2021-06-15 07:49:18 +00:00
```js
var anAdjective = "awesome!";
var ourStr = "freeCodeCamp is ";
ourStr += anAdjective;
```
2021-07-10 04:23:54 +00:00
`ourStr` teria o valor `freeCodeCamp is awesome!` .
2021-06-15 07:49:18 +00:00
# --instructions--
2021-07-10 04:23:54 +00:00
Defina `someAdjective` para uma string de pelo menos 3 caracteres e adicione para `myStr` usando o operador `+=` .
2021-06-15 07:49:18 +00:00
# --hints--
2021-07-10 04:23:54 +00:00
`someAdjective` deve ser definida para uma string de pelo menos o tamanho de 3 caracteres.
2021-06-15 07:49:18 +00:00
```js
assert(typeof someAdjective !== 'undefined' & & someAdjective.length > 2);
```
2021-07-10 04:23:54 +00:00
Você deve adicionar `someAdjective` para `myStr` usando o operador `+=` .
2021-06-15 07:49:18 +00: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
var someAdjective;
var myStr = "Learning to code is ";
```
# --solutions--
```js
var someAdjective = "neat";
var myStr = "Learning to code is ";
myStr += someAdjective;
```