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

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

#1

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.


#2

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

#3

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


#4

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


#5

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


#6

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


#7

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.


#8

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.

#9

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

#10

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


#11

this helped me so much thanks man