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

Anthony Smith
Anthony Smith
2,738 Points

method issue

When I preview this answer it shows exactly what it is asking for but still says my code is wrong, am I missing something?

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

puts mod(11, 5)

1 Answer

andren
andren
28,558 Points

It might end up looking correct, but its not quite right. The challenge wants you to return the entire answer as a String. Currently you print out the string and return the result number. And while printing and returning looks pretty similar in the REPL they are in fact quite different things.

The thing you return should be the String itself, and you should interpolate the answer inside the String just like you do with a and b like this:

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