Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSebastian Röder
13,878 PointsQuiz question about multiline strings confusing
The expected answer to the following quiz question is True
:
# 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"
2 Answers
Cristian Altin
12,165 PointsI 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.
Silver Adept
6,924 PointsI 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.