FreeCodeCamp.com - Basic JavaSript - Concatenating Strings with the Plus Equals Operator

Link:
https://www.freecodecamp.com/challenges/concatenating-strings-with-the-plus-equals-operator#?solution=%0A%2F%2F%20Example%0Avar%20ourStr%20%3D%20%22I%20come%20first.%20%22%3B%0AourStr%20%2B%3D%20%22I%20come%20second.%22%3B%0A%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0A%0Avar%20myStr%20%3D%20%22This%20is%20the%20first%20sentence.%20%22%3B%0AmyStr%20%2B%3D%20%22This%20is%20the%20second%20sentence.%22%3B%0A%0A%0A

We can also use the += 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.
Note
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.

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.

Sollution:
// Example
var ourStr = "I come first. ";
ourStr += "I come second.";

// Only change code below this line

var myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";

Komentáře

Populární příspěvky z tohoto blogu

FreeCodeCamp.com - Basic JavaSript - Passing Values to Functions with Arguments

FreeCodeCamp.com - Basic JavaSript - Word Blanks

FreeCodeCamp.com - Basic JavaSript - Understand String Immutability