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!
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
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?
Stone Preston42,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