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 trialJustin Taylor
2,221 PointsStuck on Method Returns: Part 2
I am drawing a blank on how to complete this test. I back tracked to see where I get stumped. It's applying the "return" in my method. If I leave out "return" my string comes out correct.
If I place "return" before c = a%b, only the answer shows and not the string.
If I my "puts" is before the "return c = a%b" I get "undefined local variable or method 'c' for main:Object (NameError) Did you mean? c
Thank you in advance!
def mod(a,b)
puts "The remainder of #{a} divided by #{b} is #{c}"
return c = a%b
end
puts mod(66,32)
1 Answer
andren
28,558 PointsThe challenge asks you to return the string, it does not ask you to print it, so puts
is not needed at all. If you just return the string like this:
def mod(a,b)
c = a%b
return "The remainder of #{a} divided by #{b} is #{c}"
end
Then the code will work fine.