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 trial

Ruby

Asaf Oren
PLUS
Asaf Oren
Courses Plus Student 2,220 Points

Break row after Variable in string - RUBY

I wrote this simple code:

print "What is your name? "
name = gets
print "What is your age? "
age = gets
print "What is your favorite book? "
book = gets

string = <<-info
Your name is #{name}
you are #{age} years old
and your favorite book is #{book}.
info

puts string

why in the output after every variable i'm getting break line? this is the output:

What is your name? Michael
What is your age? 31
What is your favorite book? ruby
Your name is Michael

you are 31
years old                                                                                                               
and your favorite book is ruby

Thank you all!

Asaf.

1 Answer

rdaniels
rdaniels
27,258 Points

Try putting gets.chomp not just gets. adding the .chomp gets rid of the extra lines.....