dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
62 lines
1.7 KiB
Markdown
62 lines
1.7 KiB
Markdown
---
|
|
id: 56533eb9ac21ba0edf2244b8
|
|
title: Concatenating Strings with the Plus Equals Operator
|
|
challengeType: 1
|
|
forumTopicId: 16803
|
|
dashedName: concatenating-strings-with-the-plus-equals-operator
|
|
---
|
|
|
|
# --description--
|
|
|
|
We can also use the `+=` operator to <dfn>concatenate</dfn> a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.
|
|
|
|
**Note:** Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
|
|
|
|
Example:
|
|
|
|
```js
|
|
let ourStr = "I come first. ";
|
|
ourStr += "I come second.";
|
|
```
|
|
|
|
`ourStr` now has a value of the string `I come first. I come second.`.
|
|
|
|
# --instructions--
|
|
|
|
Build `myStr` over several lines by concatenating these two strings: `This is the first sentence.` and `This is the second sentence.` using the `+=` operator. Use the `+=` operator similar to how it is shown in the example and be sure to include a space between the two strings. Start by assigning the first string to `myStr`, then add on the second string.
|
|
|
|
# --hints--
|
|
|
|
`myStr` should have a single space character between the two strings.
|
|
|
|
```js
|
|
assert(/sentence\. This/.test(myStr));
|
|
```
|
|
|
|
`myStr` should have a value of the string `This is the first sentence. This is the second sentence.`
|
|
|
|
```js
|
|
assert(myStr === 'This is the first sentence. This is the second sentence.');
|
|
```
|
|
|
|
You should use the `+=` operator to build `myStr`.
|
|
|
|
```js
|
|
assert(__helpers.removeJSComments(code).match(/myStr\s*\+=\s*(["']).*\1/g));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
let myStr;
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
let myStr = "This is the first sentence. ";
|
|
myStr += "This is the second sentence.";
|
|
```
|