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

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.