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 (Retired) Ruby Methods Method Returns: Part 2

Why isn't this working?

def mod(a, b) #write your code here puts "The reminder of #{a} divided by #{b} is: " return a%b end

puts mod(12,8)

method.rb
def mod(a, b)
  #write your code here
  puts "The reminder of #{a} divided by #{b} is: "
    return a%b
end

puts mod(12,8)

3 Answers

Steven Parker
Steven Parker
215,960 Points

:point_right: Here are a few hints:

  • you need to build the answer into the string along with the arguments
  • you should return the string, not print it out
  • return the result as the string, not separately as a value (I know, this seems a bit odd)
  • the task is only to create the method, not call it
  • check the spelling of "reminder" (remainder)

I tried this, still not working: ''' def mod(a, b) puts "The remainder of #{a} divided by #{b} is " return a%b end '''

Alan Matthews
Alan Matthews
10,161 Points

This is the overall correct method below, however you need to add some code on the commented out line to interpolate c in the string. You need to specifically return the string instead of using puts or print. In Ruby, you normally don't need to add the return since Ruby will return the last expression evaluated in a method. But in order to pass the challenge, you need return.

def mod(a, b)
  #write your code here
  return "The remainder of #{a} divided by #{b} is #{c}."
end