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

Ruby Basics - Methods - Exercise

I cannot figure out what's wrong with my current code. I received the following error message: "NameError: undefined local variable or method `a' for main:Object". Also how to handle the c part ? Is there some sort of a way to use at the end return c ?

Thanks a lot !

Mike Rogers
Mike Rogers
5,280 Points

Can you post your code?

Sorry, I thought I added it by selecting an option when asking the question but it was not the case apparently. Here it is:

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

puts mod a%b

1 Answer

Hi Nicolas,

Your method should only return that string. You don't want to output it with puts. Also, the example string has a period at the end of it so you need to add that into your string.

The code challenge will call this method for you so you don't need your last line.

Making those changes should get you to this:

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

We know that c should be the result of a%b so you can replace c with that expression.

Let me know if you're still stuck.

Hi Jason,

Thanks for your help ! By simply replacing c by a%b in your code provided above it worked.

Have a nice day !