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

Will Johnson
Will Johnson
454 Points

Turning "c" into the value of a % b.

When I run my code, I get "The remainder of 16 divided by 5 is c." How do I get it to show the remainder?

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

mod(16, 5)

2 Answers

Seth Reece
Seth Reece
32,867 Points

Hi Will,

You want to set c = a % b, then return the string "The remainder of #{a} divided by #{b} is #{c}."

Will Johnson
Will Johnson
454 Points

I appreciate your help, Seth. I followed your instructions and got this message: Bummer! Make sure you return a nicely formatted string.

When I run my code in the workspace, everything appears to come out fine. Here's my code:

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

mod(16, 5)

Seth Reece
Seth Reece
32,867 Points

Hi will,

You want to return the string, not print it. e.g.

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