2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244b7
title: Concatenating Strings with Plus Operator
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cNpM8AN'
2019-08-05 09:17:33 -07:00
forumTopicId: 16802
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
In JavaScript, when the < code > +< / code > operator is used with a < code > String< / code > value, it is called the < dfn > concatenation< / dfn > operator. You can build a new string out of other strings by < dfn > concatenating< / dfn > them together.
< strong > Example< / strong >
2019-05-17 06:20:30 -07:00
```js
'My name is Alan,' + ' I concatenate.'
```
2018-09-30 23:01:58 +01:00
< strong > Note< / strong > < br > Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
2020-03-25 08:07:13 -07:00
Example:
```js
var ourStr = "I come first. " + "I come second.";
// ourStr is "I come first. I come second."
```
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
Build < code > myStr< / code > from the strings < code > "This is the start. "< / code > and < code > "This is the end."< / code > using the < code > +< / code > operator.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: < code > myStr</ code > should have a value of < code > This is the start. This is the end.</ code >
2019-07-13 00:07:53 -07:00
testString: assert(myStr === "This is the start. This is the end.");
2019-11-27 02:57:38 -08:00
- text: You should use the < code > +</ code > operator to build < code > myStr</ code > .
2020-03-26 10:42:18 -07:00
testString: assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
2018-10-04 14:37:37 +01:00
- text: < code > myStr</ code > should be created using the < code > var</ code > keyword.
2019-07-13 00:07:53 -07:00
testString: assert(/var\s+myStr/.test(code));
2019-11-27 02:57:38 -08:00
- text: You should assign the result to the < code > myStr</ code > variable.
2019-07-13 00:07:53 -07:00
testString: assert(/myStr\s*=/.test(code));
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
var myStr; // Only change this line
2018-09-30 23:01:58 +01:00
```
< / div >
### After Test
< div id = 'js-teardown' >
```js
2018-10-20 21:02:47 +03:00
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
2018-09-30 23:01:58 +01:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
var myStr = "This is the start. " + "This is the end.";
```
< / section >