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

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