2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244ed
title: Appending Variables to Strings
challengeType: 1
2020-05-21 17:31:25 +02:00
isHidden: false
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cbQmZfa'
2019-07-31 11:32:23 -07:00
forumTopicId: 16656
2018-09-30 23:01:58 +01:00
---
## Description
< section id = '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 (< code > +=< / code > ) 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!"
```
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
Set < code > someAdjective< / code > and append it to < code > myStr< / code > using the < code > +=< / code > operator.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2019-11-27 02:57:38 -08:00
- text: < code > someAdjective</ code > should be set to a string at least 3 characters long.
2019-07-13 00:07:53 -07:00
testString: assert(typeof someAdjective !== 'undefined' & & someAdjective.length > 2);
2019-11-27 02:57:38 -08:00
- text: You should append < code > someAdjective</ code > to < code > myStr</ code > using the < code > +=</ code > operator.
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
2020-03-25 08:07:13 -07:00
// Change code below this line
2018-09-30 23:01:58 +01:00
var someAdjective;
var myStr = "Learning to code is ";
```
< / div >
### After Test
< div id = 'js-teardown' >
```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
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
var someAdjective = "neat";
var myStr = "Learning to code is ";
myStr += someAdjective;
```
< / section >