Skip to content

Instantly share code, notes, and snippets.

@jendiamond
Last active December 21, 2015 20:18
Show Gist options
  • Save jendiamond/6359930 to your computer and use it in GitHub Desktop.
Save jendiamond/6359930 to your computer and use it in GitHub Desktop.
Exercise 11 - Learn Ruby the Hard Way
# the print method prints the following string;
print "What is your name? "
# the variable "name" is assigned the input received from
# the user using the method "gets";
# "chomp" returns the cursor to a new line
name = gets.chomp()
# the print method prints the following string;
print "How old are you? "
# the variable "age" is assigned the input received from
# the user using the method "gets";
# "chomp" returns the cursor to a new line
age = gets.chomp()
# the puts method prints the string;
print "How tall are you? "
# the variable height is assignned the variable which
# is received by the user (using the method gets);
# chomp returns the cursor to a new line
height = gets.chomp()
# the puts method prints the string;
print "How much do you weigh? "
# the variable weight is assignned the variable which
# is received by the user (using the method gets);
# chomp returns the cursor to a new line
weight = gets.chomp()
# the puts method prints the string; using string interpolation the variables for age, height and weight are embedded into the string
puts "So #{name}, you're #{age} years old, #{height} tall and #{weight} pounds."
Here is a variation on this exercise...
print "What is your name? "
name = gets.chomp()
print "How many pets do you have? "
pet_amt = gets.chomp()
print "What is the name of your favorite pet? "
pet_fav_name = gets.chomp()
print "What kind of animal is your pet? "
animal = gets.chomp()
print "What is your other pet's name? "
pet_other_name = gets.chomp()
puts "So #{name}, you have #{pet_amt} pets, your favorite pet,
#{pet_fav_name}, the #{animal}, distracts you; while #{pet_other_name},
is in your fridge, eating your food."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment