Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Basics (Retired) Ruby Methods Method Returns: Part 2

Create a method called "mod" that takes two arguments, "a" and "b", and returns the remainder of "a" when divided by "b"

Right, so I have this question. Create a method called "mod" that takes two arguments, "a" and "b", and returns the remainder of "a" when divided by "b". Hint: remember the "%" operator!

I'm able to create def mod (a, b) puts a / b return %a / b end

How do I fix it?

1 Answer

Stone Preston
Stone Preston
42,016 Points

you dont need to puts anything to the console. all you need to do is return the remainder of a divided by b. to do this you use the modulo operator which is %. you use the modulo operator like any other binary mathematical operator such as +, - *, and /. It goes in between two operands. for example, to return the remainder of a variable some_variable divided by another_variable, you would use

return some_variable % another_variable

so remove the puts statement and fix the return statement