Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics Ruby Syntax Method Return Values

How to make a method return a particular value?

Challense Task:

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!)

I am stuck on this. This is all I could come up with for this challenge.

a = 3 def three end puts a

b = 5 def five end puts b

methods.rb
a = 3
  def three
end


b = 5
  def five
end

1 Answer

Steffeni Veren
Steffeni Veren
7,259 Points

Hi there, In order to declare a method, you'll want to surround the new method with def and end. So in order to create a method called three that can be called like three(), you would write: def three puts 3 end

Reach out if you need any other help!!

Hey there! Thank you but, they specifically ask that you don't code using "puts" because they didn't want an argument. I figured it out though! It's:

def three return 3 end

def five return 5 end