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 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

method.rb
def mod(a, b)
  #write your code here
end

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}."