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

Raul Grigoriu
Raul Grigoriu
1,060 Points

Help on a challenge!

Bummer! Make sure you return a nicely formatted string.

I do not really understand what is not nice in my string really? Can somebody illuminate me please?
Thank you in advance!:)

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

puts mod(5, 9)

3 Answers

You are actually not returning your answer as a string. You are printing (puts) a string and then returning just the answer. Try returning the string with your answer:

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

puts mod(5, 9)

Also make sure all your string interpolations have a hash(#) in front of them. Let me know if you still have questions.

Raul Grigoriu
Raul Grigoriu
1,060 Points

Thanks a million Ryan, for now I am good to go but I am most sure in the future...

Kourosh Raeen
Kourosh Raeen
23,732 Points

Hi Raul - There should only be a return statement inside the method which returns the sentence "The remainder of a divided by b is c." Use string interpolation inside that string to replace a, b, and c with their actual values and don't display anything.

Raul Grigoriu
Raul Grigoriu
1,060 Points

Thank for your quick reply Kourosh! :)