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 trialSanchari Bhattacharya
Courses Plus Student 5,751 PointsUse string interpolation to return the remainder inside the sentence βThe remainder of a divided by b is c.β where a is
I am doing this code. I need help with understanding what they want
def mod(a, b)
#write your code here
end
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Sanchari,
I'll use an example with actual numbers to see if that helps you understand what the challenge wants.
Suppose the challenge tester calls your method like this:
mod(7, 3)
Your method should return the string "The remainder of 7 divided by 3 is 1."
You have to achieve that by using the local parameters a
and b
and string interpolation.
Let me know if you're still stuck.
Sanchari Bhattacharya
Courses Plus Student 5,751 Pointsso it is asking for return "The remainder of #{a} divided by #{b} is #{c}."
Jason Anello
Courses Plus Student 94,610 PointsThat's close except c
is an undefined variable. a and b will be whatever was passed in but c does not have a value. It needs to be the result of the mod operation.
You could either add one line before that where you assign a value to c
c = a % b
# and then the return statement
or you could skip the c variable and put the mod expression directly in place of c
return "The remainder of #{a} divided by #{b} is #{a % b}."