Welcome to the Treehouse Community
Looking to learn something new?
Sebastian Röder13,878 Points
Quiz question about multiline strings confusing
The expected answer to the following quiz question is
# The following code would create a valid string in Ruby with 3 lines in it: string = " My Ruby string here Is created in three lines This is a haiku"
I gave the answer
False because the code sample actually creates a string with 4 lines in it (an empty line at the beginning and than the 3 lines of text. I was a little confused that my answer was not accepted as correct.
I would recommend formatting the multiline string in the example with the first line of text following immediately after the opening
"(the same way it is done in the video) to avoid any confusion, because then the string actually has 3 lines instead of 4.
# The following code would create a valid string in Ruby with 3 lines in it: string = "My Ruby string here Is created in three lines This is a haiku"
Cristian Altin12,165 Points
I agree. Pasting the code in the irb gave this output: => "\nMy Ruby string here\nIs created in three lines\nThis is a haiku"
It's 4 lines. The question would be correct by saying that it would create a valid string in Ruby with 3 newlines "\n" in it. But also the string text would need to change and would lose being a haiku (which btw requires three lines with 5 syllables in the first and 7 in the second and 5 in the third).
Hence your suggestion is correct IMHO.
I agree as well. The newline at the beginning of the code produces a blank line and then three more lines after that, which for me, reads four lines, not three. Your code suggestion makes sense - remove the newline, and then the string is properly three lines long.