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

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,323 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.