2.0 KiB
2.0 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244b7 | Concatenating Strings with Plus Operator | 1 | https://scrimba.com/c/cNpM8AN | 16802 |
Description
+
operator is used with a String
value, it is called the concatenation operator. You can build a new string out of other strings by concatenating them together.
Example
'My name is Alan,' + ' I concatenate.'
Note
Watch 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. " + "I come second.";
// ourStr is "I come first. I come second."
Instructions
myStr
from the strings "This is the start. "
and "This is the end."
using the +
operator.
Tests
tests:
- text: <code>myStr</code> should have a value of <code>This is the start. This is the end.</code>
testString: assert(myStr === "This is the start. This is the end.");
- text: You should use the <code>+</code> operator to build <code>myStr</code>.
testString: assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
- text: <code>myStr</code> should be created using the <code>var</code> keyword.
testString: assert(/var\s+myStr/.test(code));
- text: You should assign the result to the <code>myStr</code> variable.
testString: assert(/myStr\s*=/.test(code));
Challenge Seed
var myStr; // Only change this line
After Test
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
Solution
var myStr = "This is the start. " + "This is the end.";