Ruby Ruby Basics Ruby Syntax Method Return Values

Whats wrong

I ran the code in my own linux box. It worked.

methods.rb
def three(a)
  a=3
  return a
end

def five(b)
  b=5
  return b 
end

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 143,922 Points

Hi Sherman,

You have a couple of issues here.

First, the instructions need to be followed exactly as they are stated. Here the instructions does not say anything about a parameter for the method, so the parenthesis should be empty ==> def method_name() Note: you could eliminate the parenthesis all together, but I like them there, so the "no parameters" is clear to anyone reading the code.

Second, the instructions do not say to assign a value to any variable, so the method should just return the hard-coded value it asks for. This can be done with the return method, or in Ruby, the last line of a method will automatically be returned, so you don't even need the return for this method.

The correct method would look like this:

def three()   # No parameters are asked for, so the () should be empty
  3           # This is the last line of the method, so the value will be an implicit return
end

Keep Coding! :) :dizzy: