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

I don't know where i'm going wrong. Can i get some assistance.

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

return c = a % b end puts mod(12, 5, c)

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

  return c = a % b
end
puts mod(12, 5)

1 Answer

Mike Hickman
Mike Hickman
19,817 Points

Hi Samory,

You're on the right track, but you need to tweak a few things with your code.

First, let's setup variable c to get the remainder of a % b.

c = a % b

Now we'll always have that value ready to go with the c variable. It asks us to return the full sentence, so we don't need a print or puts in this exercise at all. It wants us to interpolate all of the values of a, b and c in the return statement.

def mod(a, b)
  c = a % b
  return "The remainder of #{a} divided by #{b} is #{c}."
end

So, if the actual call to the mod method is mod(2, 3), the return would be The remainder of 2 divided by 3 is 2.

Hope this makes sense.

Have fun,

Mike