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

Raymond Rowe
Raymond Rowe
6,174 Points

What's wrong?

It says make sure you return a nicely formatted sentence

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

You should do this:

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

Hi xela888 - There's really no need for an extra variable to hold the string. It's much cleaner to just return the string. In fact, we could also get rid of c as well:

return "The remainder of #{a} divided by #{b} is #{a%b}."

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

You have both return and puts. It should be just a return statement. Also you need a period at the end of the string:

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