Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Input and Output in Ruby!
You have completed Practice Input and Output in Ruby!
Preview
Now that you've coded your solution to the practice problem, I'll show you how I did it.
Here's my code:
# Prompt the user to enter a verb, and store what they enter
# in a variable named "verb".
print "Please enter a verb: "
verb = gets.chomp
# Prompt the user to enter a noun, and store what they enter
# in a variable named "noun".
print "Please enter a noun: "
noun = gets.chomp
# Prompt the user to enter an adjective, and store what they
# enter in a variable named "adjective".
print "Please enter an adjective: "
adjective = gets.chomp
# Prompt the user to enter a second noun, and store what they
# enter in a variable named "noun2".
print "Please enter another noun: "
noun2 = gets.chomp
# Fill in the #{} marker to include the contents of the
# "verb" variable in the below string.
puts "One day, I decided to learn to #{verb} in Ruby."
# Use the contents of the "noun" variable in this sentence.
puts "So I turned on my #{noun} and logged in to Treehouse."
# Use the contents of the "adjective" variable in this sentence.
puts "Their teachers were really #{adjective}."
# Use the contents of the "noun2" variable in this sentence.
puts "In no time, I'd learned to program a simple #{noun2}!"
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
so on, stored the answers and used those
answers to fill-in blanks in a story.
0:00
Here's my solution.
0:00
It's okay if yours is slightly different,
but if you see something interesting in my
0:02
code, you should consider borrowing
it to improve your own program.
0:05
So, first we needed to prompt
the user to enter a verb.
0:09
I called the print method to display
the prompt and passed a string to it.
0:13
The reason I used print instead of put
add, is that print doesn't add a new
0:16
line on to the end of whatever string
it prints, so that the prompt appears
0:21
right there on the same line
where the user types their entry.
0:26
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up