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

Ruby Ruby Basics (Retired) Ruby Methods Method Returns: Part 2

Use string interpolation to return the remainder inside the sentence β€œThe remainder of a divided by b is c.” where a is

I am doing this code. I need help with understanding what they want

def mod(a, b)
  #write your code here

2 Answers

Hi Sanchari,

I'll use an example with actual numbers to see if that helps you understand what the challenge wants.

Suppose the challenge tester calls your method like this:

mod(7, 3)

Your method should return the string "The remainder of 7 divided by 3 is 1."

You have to achieve that by using the local parameters a and b and string interpolation.

Let me know if you're still stuck.

so it is asking for return "The remainder of #{a} divided by #{b} is #{c}."

That's close except c is an undefined variable. a and b will be whatever was passed in but c does not have a value. It needs to be the result of the mod operation.

You could either add one line before that where you assign a value to c

c = a % b
# and then the return statement

or you could skip the c variable and put the mod expression directly in place of c

 return "The remainder of #{a} divided by #{b} is #{a % b}."