Jason Mcdon Jason Mcdon - 6 months ago 20
Ruby Question

Gets.chomp not working

I am currently learning Ruby and I am stuck in the 11th exercise of Learn Ruby the Hard Way and I have to write this:

print "How old are you? "
age = gets.chomp()
print "How tall are you? "
height = gets.chomp()
print "How much do you weigh? "
weight = gets.chomp()

puts "So, you're #{age} old, #{height} tall and #{weight} heavy."

And I have to get this:

How old are you? 35
How tall are you? 6'2"
How much do you weigh? 180lbs
So, you're 35 old, 6'2" tall and 180lbs heavy.

but I get this:

How old are you?
How tall are you?
How much do you weigh?
So, you're old, tall and heavy.

So that means that gets.chomp is not working and I don't understand anything.


You are supposed to enter values, not just press enter, when prompted after running the program:

# ⇓   prompt ⇓   ⇓⇓ YOUR INPUT!!! 
How old are you? 35

Sidenote: parentheses after chomp are redundant and not ruby idiomatic.