Ask A Question

Notifications

You’re not receiving notifications from this thread.

Help

Iaininio asked in Ruby

Implement a Ruby method can_you_vote? that returns true or false depending on the given age.

This method should take one arguments (age), an Integer, and return a Boolean(true/false).
can_you_vote?(18) & can_you_vote?(30) should return true
can_you_vote?(16) should return false.

This is a question i was provided however i am constsantly getting syntax errors, i am in my first week of Ruby and have really hit a dead end.

my sytax error filled answer so far is:

def can_you_vote?(age)

if age > 17
print "True"
if (age) < 18
print "False"
end

can_you_vote?(18)
can_you_vote?(16)
can_you_vote?(30)

Any direction on where i am going wrong would be greatly appreciated

Reply

Your first if doesn't have an end.

Try writing it like this:

def can_you_vote?(age)
  if age >= 17
        print "True"
    else
      print False
    end
end
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.