Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Basics Ruby Syntax Method Return Values

Kristen Kerchhoff
Kristen Kerchhoff
1,895 Points

Methods working locally but in online editor

When I run the methods in this file locally the correct numbers are returned.

However when I run this in the online editor as part of a challenge task it returns "wrong number of arguments (given 0, expected 2)"

Could someone please advise what the correct format should look like?

def three(length, width)
    return length + width

def five(length, width)
    return length - width

puts three(1, 2)
puts five(7, 2)

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,692 Points

Hi Kristen,

While the code above is correct in syntax, it is not what the Challenge is asking for. I'm not sure where you are getting the code from, but instructions for Code Challenges need to be followed exactly or the task will fail with a Bummer!.

You are getting that error because there are supposed to be no arguments for the methods, but you have two in both. The instructions simply say to:

Define a method named three that returns the number 3. Also define a method named five that returns the number 5.

The instructions say nothing about calculations or even calling the methods, nor do they say anything about arguments.

A good rule to remember is: "If the instructions don't ask for it... don't do it." :smirk:

I feel you just really over thought this one. The methods just needs to be simplified:

def three()
  return 3

def five()
  return 5

Other than that... Nice work on the method syntax! :) :dizzy:

Jay McGavren
Jay McGavren
Treehouse Teacher

This challenge seems to have been confusing a lot of people. Made some clarifications to the directions:

Define a method named three that always returns the number 3. Also define a method named five that always returns the number 5. Neither method should take any arguments. (We know, these methods aren't especially useful. We just want to see if you know how to make a method return a particular value!)