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

Dharma Teja
PLUS
Dharma Teja
Courses Plus Student 5,206 Points

In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but

can anyone help this question

method.rb
def mod(a, b)
  #write your code here
  puts "Reminder of #{a} and #{b} is #{c} " 
  return c

end

mod()

2 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

You're close, but this challenge wants you to return the string from the mod method, not print it out. And there is no c variable; the challenge says:

where... c is the value of a % b

So you should do this:

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

Or even just this:

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

I don't remember if that one needed to return c or not at the end of the method. Really all you need to do here is create a variable c, and pass in two numbers when calling your method.

where inputting your code a solution could be c = a % b

then call mod with 2 numbers mod(5,2)

output should be Reminder of 5 and 2 is 1