Elsif, else, puts


#1

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?"
age=gets.chomp
if #{age} < 30
    puts "You have much to learn."
elsif
    #{age} > 30
    puts "You are Wise."
else
    #{age} equals 30
    puts "Spot On."
end

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.
nil

Hope that makes sense....

Your help will be much appreciated.


#2

@cho53n,
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
if

and if you read
http://docs.ruby-lang.org/en/2.0.0/syntax/control_expressions_rdoc.html
you will see that the IF and the ELSIF take a condition
but the ELSE does not..


#3

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