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 trialNicolas Philemotte
382 PointsRuby 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 !
Nicolas Philemotte
382 PointsSorry, 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
Jason Anello
Courses Plus Student 94,610 PointsHi 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.
Nicolas Philemotte
382 PointsHi Jason,
Thanks for your help ! By simply replacing c by a%b in your code provided above it worked.
Have a nice day !
Mike Rogers
5,280 PointsMike Rogers
5,280 PointsCan you post your code?