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

Alistair Mackay
Alistair Mackay
7,812 Points

Stuck on Modify return part 2

There's an error in the syntax that is not marrying up with what the question is looking for.

I know that the question is asking me to return the value of c, which a % b but the way I'm laying it out appears to be wrong.

Alternatively I have tried this form and got the results to print correctly according to output but it is not correct as far as this exercise goes. def mod (a, b) puts "the remainder of #{a} divided by #{b} is #{a % b}." end

mod (5, 2)

Any assistance with figuring out exactly what the exercise is looking for would be greatly appreciated!

-PC

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

mod (5, 2)

1 Answer

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

Like you said you have to return the string instead of using the "puts" function. Don't forget to put the "dot" at the end of the formatted string.

def mod(a, b)
  return "The remainder of #{a} divided by #{b} is #{a % b}."     <---- the message ends with a dot
end

I hope that helps a little bit

Alistair Mackay
Alistair Mackay
7,812 Points

Thanks Carlos, that did the trick.