You can create different lines by adding in escape characters. An escape character is preceded by a backslash. The escape character for a new line is “n”. So, if I wanted a string to output to different lines, I could do:
var str1 = "first linesecond linethird line";
console.log(str1);
// first linesecond linethird line
var str2 = "first line\nsecond line\nthird line";
console.log(str2);
// first line
// second line
// third line
If that isn’t clear enough, you could also do it as:
Oh, maybe I misunderstood. Concatenation would be adding strings together. Just a simple + will do that.
``
var str1 = "To be ";
var str2 = "or not ";
var str3 = “to be”;
It’s really hard to tell - the JS that you provided is not a valid JS statement so it’s difficult to tell what you started with.
The “concatenation” part is using the plus sign (+) to add strings together. Adding in the \n in appropriate spots of a string tells it where to break the lines.
If you have the strings in an array, you could also use .join().
var haiku = ['On Udacity', 'Concatenating the strings', 'Helps me write haikus.'];
console.log(haiku.join('\n'));
>>> On Udacity
Concatenating the strings
Helps me write haikus.
Programming Quiz: Yosa Buson (2-6)
*/
var str1 = "Blowing from the west"
var str2 = "\nFallen leaves gather"
var str3 = "\nIn the east."
var haiku = str1 + str2 +str3;
console.log(haiku);