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 know the code is right that I am putting in for this problem. I tested it in the workspace. Please help.

If anyone can help me let me know.

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

5 Answers

Zach Swift
Zach Swift
17,984 Points

You are very close!

You are missing a period at the end of the sentence AND they're asking you to return it. I think they're looking for the 'return' keyword.

Ok. Let me try that.

That didn't work. I added the period. It also asks to display "c".

Zach Swift
Zach Swift
17,984 Points

just replace the 'puts' keyword with 'return' and that made it pass for me.

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

that's what I mean. Is that what you tried?

That worked. Thanks!

Alan Matthews
Alan Matthews
10,161 Points

See above. The return is not necessary as Ruby always returns the last evaluated expression.

Thanks Alan. I put in the period and it didn't work. Is there anything else I am missing?

Zach Swift
Zach Swift
17,984 Points

That's very true, but I believe they are looking for the return keyword. Because it passes only with 'return' .

Alan Matthews
Alan Matthews
10,161 Points

Sorry if I confused everyone. Use return instead of puts or print in order to make the exercise pass. I was just mentioning that normally you would not need to use return since Ruby will evaluate the last expression and return that.

I know how to return, but how would I get it in the string?