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

Jessica Pace
PLUS
Jessica Pace
Courses Plus Student 274 Points

Why is my method not working to produce the remainder of a divided by b?

def mod(a, b) puts "remainder of #{a} when divided by #{b}" return a / b end

puts mod(6,2)

method.rb
def mod(a, b)
  puts "remainder of #{a} when divided by #{b}"
  return a / b
end

puts mod(6,2)

2 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Jessica! You are doing way too many stuff. All you've to do is

  • to create a function "mod" that takes two arguments, a and b
def mod(a, b)
end
  • now , you have to return the remainder of the division of a and b. All You have to do is use "%"(modulous) operator. Modulous operator throws the remainder of the division of two numbers, whereas "/"(division) operator throws the quotient.
def mod(a, b)
  return a %b
end

I hope it helped! (:

Jessica Pace
Jessica Pace
Courses Plus Student 274 Points

Thanks so much...yeah my answer was simplified but after trying adding stuff I thought might fix the problem this was my last try! haha... I understand clearly now though!

Ari Misha
Ari Misha
19,323 Points

Haha i know! Sometimes few questions on here couldnt be more obscure and errors doesnt help either. Your best bet is to follow the instructions given in the questions. I mean , many times your code might work in an IDE but it wont work in the editor attached to the challenges. So yeah as long as you're doing whatever they're askin' you to, you're all good haha (: