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

Kai Huang
Kai Huang
9,369 Points

My answer is wrong but I think it is correct

Is there anything wrong with my code?

Justin Horner
Justin Horner
Treehouse Guest Teacher

Hello Kai,

Please post your code so we can check it out.

Kai Huang
Kai Huang
9,369 Points

Oh sorry, Didn't notice I didn't add the code in. Do let me know why this answer isn't working. Thanks!

def mod(a, b)
 return "The remainder of #{a} divided by #{b} is #{a%b}"
end
Jordan Gauthier
Jordan Gauthier
5,552 Points

I haven't learned ruby yet, but could it be that you are attempting to get the remainder of a / c rather than a / b?

Instead of #{a%c}, should it instead be #{a%b}?

2 Answers

Kai Huang
Kai Huang
9,369 Points

Ah I have found out the mistake, apparently I need to set

c = a % b

first before inserting #{c} into the puts statement

My answer came in a little late here but you don't need to create a c variable. What you had posted above was fine with the exception of the missing period.

Hi Kai,

The only issues is that you're missing a period to end the sentence. The challenge is looking for an exact match on the string and the example in the instructions has a period at the end.

Sometimes the challenges are a little lenient and will accept answers without things like periods but the best thing to do is always try to match the output exactly.