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 Ruby Basics (Retired) Ruby Methods Practice Makes Perfect!

Joe Williams
Joe Williams
4,014 Points

In Ruby, how do I prevent my ? from bumping down a line?

As the video suggested, I'm practicing making a questionnaire that asks what the user's favorite movie is.

However, every time I run this the question mark doesn't cooperate.

puts "Hello!"
puts "What is your favorite movie?" 
favorite_movie = gets
puts "Oh, your favorite movie is #{favorite_movie} ?" 

How do I keep the question mark from bumping down a line?

1 Answer

Alex Stophel
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Stophel
iOS Development Techdegree Student 11,552 Points

Hi Joe,

You need to add .chomp to the end of gets.

puts "Hello!"
puts "What is your favorite movie?" 
favorite_movie = gets.chomp
puts "Oh, your favorite movie is #{favorite_movie}?" 

Chomp removes that pesky newline from the end of the user input before being interpolated into the string.