Elsif, else, puts


Hi Everyone,

First timer here : )

I'm kinda perplex on this code I'm trying to solve for this exercise

print"What is your age?"
if #{age} < 30
    puts "You have much to learn."
    #{age} > 30
    puts "You are Wise."
    #{age} equals 30
    puts "Spot On."

When I enter an value it gives me all the 'puts' and not the individual ones

What is your age? 30
You have much to learn.
You are Wise.
Spot On.

Hope that makes sense....

Your help will be much appreciated.


You should understand that if you use #
you are using Ruby's line-comment character

Thus if you write
if #{age} < 30
the interpreter will see it as

and if you read
you will see that the IF and the ELSIF take a condition
but the ELSE does not..


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.