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 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,274 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,274 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 (: