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 1

Eric Moen
PLUS
Eric Moen
Courses Plus Student 2,348 Points

I can't see to get this right https://teamtreehouse.com/library/ruby-basics/ruby-methods/method-returns-part-1

I've tried repeatedly to get through this code challenge and this one has me stuck. I really need some guidance, please.

https://teamtreehouse.com/library/ruby-basics/ruby-methods/method-returns-part-1

method.rb
def mod(a, b)

end

2 Answers

James Walton
James Walton
10,292 Points

You've got the first part correct. After that, the task is just to ask the method to return the remainder of "a" when divided by "b." Simply write the method's return value as a%b.

def mod(a , b)
  return a % b
end
james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you just put a return statement in the body of the function, returning what it asks for. the modulo or mod operator % returns the remainder of division, so if 8 divided by 5 is 1 with a remainder of 3, then 8 % 5 = 3.