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

Akshay Ramdasi
Akshay Ramdasi
14,065 Points

problem solving in this challenge

Use string interpolation to return the remainder inside the sentence “The remainder of a divided by b is c.” where a is your “a” variable, b is your “b” variable, and c is the value of a % b.

method.rb
def mod(a, b)
  #write your code here
  c = "The remainder of #{a} divided by #{b} is c: "
  return a%b
end

3 Answers

You're really close, you just have it mixed up a little bit.

def mod(a, b)
  #write your code here
  c = a % b
  return "The remainder of #{a} divided by #{b} is #{c}."
end

We need to get the value of C which is the remainder of A divided by B so we can do that by making a 'c' variable and assigning it the value of that division. Then it is asking to return a complete sentence that uses interpolation to show the actual values, so now that we have the value of 'c' we can use return to format our sentence based on the instructions.

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

So what the code challenge is asking is to return the remainder inside the sentence. That's what goes after the return statement.

c is the variable that you set to the remainder and then you use sting interpolation to replace the a and b in the sentence with the values that are passed in and c with the value that you calculated with the variable:

def mod(a, b)
  #write your code here
  c = a%b
  return "The remainder of #{a} divided by #{b} is #{c}."
end

does that help?