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 trialWill Johnson
454 PointsTurning "c" into the value of a % b.
When I run my code, I get "The remainder of 16 divided by 5 is c." How do I get it to show the remainder?
def mod(a, b)
puts "The remainder of #{a} divided by #{b} is c."
return a % b
end
mod(16, 5)
2 Answers
Seth Reece
32,867 PointsHi Will,
You want to set c = a % b, then return the string "The remainder of #{a} divided by #{b} is #{c}."
Seth Reece
32,867 PointsHi will,
You want to return the string, not print it. e.g.
def mod(a, b)
c = a % b
return "The remainder of #{a} divided by #{b} is #{c}."
end
Will Johnson
454 PointsWill Johnson
454 PointsI appreciate your help, Seth. I followed your instructions and got this message: Bummer! Make sure you return a nicely formatted string.
When I run my code in the workspace, everything appears to come out fine. Here's my code:
def mod(a, b) c = a % b puts "The remainder of #{a} divided by #{b} is #{c}." return a % b end
mod(16, 5)