HELPP!Build a string using concatenation by combining the lines from this famous haiku poem by Yosa Buson

I am tottally stucked in this UDACITY quiz guys!! Give me some help:

Build a string using concatenation by combining the lines from this famous haiku poem by Yosa Buson.

Blowing from the west
Fallen leaves gather
In the east.
Each string should be printed on its own line.

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:

var str2 = "first line" + "\n" + "second line" + "\n" + "third line";

https://mathiasbynens.be/notes/javascript-escapes

var haiku = (“Blowing from the west\ Fallen leaves gather\ In the east.”");/* concatenate the strings here */
console.log(haiku);

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”;

var str = str1 + str2 + str3;

console.log(str);
// To be or not to be

I will try it like that ksjazz,the other ways are not working

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.

This is what I’ve done :

/*

  • 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);

Your can certainly do it that way, but you don’t need to store strings in variables just to concatenate them.

console.log(“Blowing from the west \n” + “Fallen leaves gather \n” + “In the east.”);

this helped me so much thanks man

1 Like