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

J Quinn
J Quinn
2,439 Points

How is this wrong?

It runs nicely on my desktop, but not for the ruby basic exercise. Please help.

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

1 Answer

Jacob Herrington
Jacob Herrington
15,835 Points

Really close! You clearly understand the math that goes into this question, you're just struggling with the flow of the program.

Think about what you are asking the computer to do from an algorithmic standpoint:

def mod(a, b)
  # Do some math
  # Save the results of that math
  # Return some results based on the math
end

I'm betting you might already have noticed the problem, but in case you didn't here is the code. I'm sure you'll realize how easily fixed your mistake is:

def mod(a, b)
  c = a % b                                                # Do some math, save the results
  return "The remainder of #{a} divided by #{b} is #{c}."  # Return some results
end