Ruby Ruby Basics Ruby Syntax Method Return Values

Samuel Joseph
Samuel Joseph
5,400 Points

I am trying to return 5, but it keeps telling me that I am wrong. def five(b) b = 5 return b end

How can I find my correct answer based on what I have input?

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

def five(b)
  b = 5
  return b
end

1 Answer

andren
andren
28,360 Points

The issue is that you have defined parameters for the functions. Parameters are the thing you write within the parenthesis of the function definition. They are used to pass data into a function when it is called, since your functions are not meant to have data passed to them they should not have parameters.

Like this:

def three() # Don't declare "a" as a parameter
  a = 3  
  return a
end

def five() # Don't declare "b" as a parameter
  b = 5
  return b
end

Also while not invalid it is not really necessary to assign the numbers to a variable if you are just going to return them right away. You can instead just return the numbers directly.

Like this:

def three()
  return 3
end

def five()
  return 5
end