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

I keep receiving this error message from the code challenge "make sure you're returning a string from the mod method."

I am working my way through Methods in Ruby basics and I'm stuck here at this particular coding challenge. I'm not sure why I keep getting the error message I detailed above. I'm also not sure how to assign the variable "C" the value described in the instructions above. If there are any tips or hints that anyone could give to help me out, that would be great. Thank you very much.

method.rb
#Print out that we're dividing two numbers together. 
#And then print out the remainder of those two numbers.
def mod(a, b)
  puts "Dividing #{a} and #{b}:"
  return a % b 
end

puts mod(4,2)

1 Answer

Ari Misha
Ari Misha
19,286 Points

Hiya Javan! You're not following the instructions given in the challenges. You've to return variables "a", "b" and "c" in the single string in the function. Where "c" is "a % b". Also you dont need to "puts" or even type "return" in your function 'coz ruby does an implicit "return", which , in simple words, means that the last statement in the function gets return by default so yeah this is how your code should look like:

def mod(a, b)
  "the remainder of #{a} divided by #{b} is #{a % b}"
end

Hello Ari,

Thank you for your response. I was definitely not approaching it in the right way. I really appreciate your input, it was very helpful.