2021-02-06 04:42:36 +00:00
---
id: 56533eb9ac21ba0edf2244ed
2021-03-09 08:51:59 -07:00
title: Agrega variables a cadenas
2021-02-06 04:42:36 +00:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cbQmZfa'
forumTopicId: 16656
dashedName: appending-variables-to-strings
---
# --description--
2021-03-09 08:51:59 -07:00
Al igual que podemos construir una cadena sobre múltiples líneas a partir de las cadenas < dfn > literales</ dfn > , también podemos añadir variables a una cadena usando el operador "más igual" (`+=` ).
2021-02-06 04:42:36 +00:00
2021-03-09 08:51:59 -07:00
Ejemplo:
2021-02-06 04:42:36 +00:00
```js
2021-10-27 15:10:57 +00:00
const anAdjective = "awesome!";
let ourStr = "freeCodeCamp is ";
2021-02-06 04:42:36 +00:00
ourStr += anAdjective;
```
2021-03-09 08:51:59 -07:00
`ourStr` tendrá el valor de `freeCodeCamp is awesome!` .
2021-02-06 04:42:36 +00:00
# --instructions--
2021-03-09 08:51:59 -07:00
Establece `someAdjective` a una cadena de al menos 3 caracteres y añádelo a `myStr` usando el operador `+=` .
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-09 08:51:59 -07:00
`someAdjective` debe ser establecido a una cadena de al menos 3 caracteres.
2021-02-06 04:42:36 +00:00
```js
assert(typeof someAdjective !== 'undefined' & & someAdjective.length > 2);
```
2021-03-09 08:51:59 -07:00
Debes añadir `someAdjective` a `myStr` usando el operador `+=` .
2021-02-06 04:42:36 +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
2021-10-27 15:10:57 +00:00
const someAdjective = "";
let myStr = "Learning to code is ";
2021-02-06 04:42:36 +00:00
```
# --solutions--
```js
2021-10-27 15:10:57 +00:00
const someAdjective = "neat";
let myStr = "Learning to code is ";
2021-02-06 04:42:36 +00:00
myStr += someAdjective;
```