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 trialM J
7,322 PointsHow 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
a = 3
def three
end
b = 5
def five
end
1 Answer
Steffeni Veren
7,259 PointsHi 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!!
M J
7,322 PointsM J
7,322 PointsHey 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