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

What is this Ruby Challenge asking me to do?

This is the Ruby basics course. It is very basic in that I've been programming in Java, JavaScript, C, Python, etc. and just wanted to learn about Ruby now. I can open a work-space and build a ruby script that does just what is requested in the challenge. It is the last challenge on this course. It keeps telling me "Bummer..." Here is the challenge: "In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. 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."

I found a few ways to make this work. None of those ways is acceptable, though.
I first set c = a % b and that gives me all the variables. I realized that the challenge wanted me to return the sentence with the variables. That seems simple enough. I discovered you can even do return puts "The remainder of #{a} divided by #{b} is #{c}." Or I could start the sentence with a puts on the first line after calculating c and then return c. That could be tested and shown to work with ruby puts method.rb and it works fine. So, what's the challenge asking that I don't understand? Thanks, Bruce

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

1 Answer

Tri Pham
Tri Pham
18,671 Points

I believe the problem you're having is that you're using puts. puts prints out something to the console but returns nil. As in c = puts "hello" would result in c.nil? being true. So your function returns nil but prints to the console the right statement. The question only asks you to return the right statement.