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

Dimitrios Kavadas
Dimitrios Kavadas
2,942 Points

Modulus Challenge trouble

Hello,

I am trying to finish my challenge and my code is not accepted. I tried it in the Workspace and works out just right. Could someone advise me where I am going wrong?

Here is my code:

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

Thanks.

Dimitrios

2 Answers

Dimitrios Kavadas
Dimitrios Kavadas
2,942 Points

Should have been return instead of puts. Anyone know the difference?

Hi Dimitrious,

puts is going to print the string to the screen and it's essentially lost at that point.

With return you're returning that string back to the code that called the method. That means you can save it in a variable and do other things with it. And even still print it later with puts. You have a lot more flexibility when your methods return values instead of printing them out.