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

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