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

Jorge Garcia
Jorge Garcia
6,496 Points

String interpolation

I have no idea how to move on from this. I feel like i've tried everything that I know and it's not doing it.

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

4 Answers

nulled
nulled
1,890 Points

What you have is close. This should work:

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

Hi Jorge - Instead of displaying the string with puts you need to return it, so change puts to return and remove the other return statement. Also, you need to use string interpolation where you have c in the string. That's where you need to use a%b.

Hi, the best way to do it is this:

def mod(a, b)
    return "The remainder of #{a} divided by #{b} is #{a % b}."
end
Jorge Garcia
Jorge Garcia
6,496 Points

That did it!! Thank you all so much!