2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244ed
title: Appending Variables to Strings
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cbQmZfa'
2019-07-31 11:32:23 -07:00
forumTopicId: 16656
2021-01-13 03:31:00 +01:00
dashedName: appending-variables-to-strings
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
Just as we can build a string over multiple lines out of string < dfn > literals</ dfn > , we can also append variables to a string using the plus equals (`+=` ) operator.
2020-03-25 08:07:13 -07:00
Example:
```js
var anAdjective = "awesome!";
var ourStr = "freeCodeCamp is ";
ourStr += anAdjective;
// ourStr is now "freeCodeCamp is awesome!"
```
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Set `someAdjective` to a string of at least 3 characters and append it to `myStr` using the `+=` operator.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`someAdjective` should be set to a string at least 3 characters long.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(typeof someAdjective !== 'undefined' & & someAdjective.length > 2);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
You should append `someAdjective` to `myStr` using the `+=` operator.
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --after-user-code--
2018-09-30 23:01:58 +01:00
```js
2018-10-20 21:02:47 +03:00
(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');
})();
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
// Change code below this line
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
var someAdjective;
var myStr = "Learning to code is ";
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
var someAdjective = "neat";
var myStr = "Learning to code is ";
myStr += someAdjective;
```