* fix: remove example code from challenge seed * fix: remove declaration from solution * fix: added sum variable back in * fix: reverted description back to original version * fix: added examples to description section * fix: added complete sentence Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: corrected typo Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: reverted to original desc with formatted code * fix: removed unnecessary code example from description section Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: failiing test on iterate through array with for loop * fix: changed to Only change this line Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: moT01 <tmondloch01@gmail.com>
2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244b8 | Concatenating Strings with the Plus Equals Operator | 1 | https://scrimba.com/c/cbQmmC4 | 16803 |
Description
+=
operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.
NoteWatch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Example:
var ourStr = "I come first. ";
ourStr += "I come second.";
// ourStr is now "I come first. I come second."
Instructions
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 editor. Start by assigning the first string to myStr
, then add on the second string.
Tests
tests:
- text: <code>myStr</code> should have a value of <code>This is the first sentence. This is the second sentence.</code>
testString: assert(myStr === "This is the first sentence. This is the second sentence.");
- text: You should use the <code>+=</code> operator to build <code>myStr</code>.
testString: assert(code.match(/\w\s*\+=\s*["']/g).length > 1 && code.match(/\w\s*\=\s*["']/g).length > 1);
Challenge Seed
// Only change code below this line
var myStr;
After Test
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
Solution
var ourStr = "I come first. ";
ourStr += "I come second.";
var myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";