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 trialEthan Klein
733 Pointsc is a % b
I'm currently having trouble finishing this code while only having two arguments instead of three.
def mod(a, b)
return ("The remainder of #{a} divided by #{b} is #{c}.");
puts a % b
end
mod(100, 5)
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsTo add to Andren's answer ...
You could also eliminate the c = a % b
line and do the equation right inside of the interpolation.
def mod(a, b)
return ("The remainder of #{a} divided by #{b} is #{a % b}.");
end
andren
28,558 PointsYou aren't limited to only using passed in arguments in a function, you can create your own variables. You know that c
is meant to hold a % b
so you can just create it yourself:
def mod(a, b)
c = a % b
return "The remainder of #{a} divided by #{b} is #{c}."
end
You also don't need to print anything with puts
to pass this task. And for the record anything below a return
statement is never executed anyway, since the function stops once a return
is hit.
Note that I also removed the parentheses and semicolon from your return
statement, as they are not necessary.
Ethan Klein
733 PointsThank you!
Ethan Klein
733 PointsEthan Klein
733 PointsThank you for the reply. Putting it in the interpolation is very clean. :)