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 trialMubeen khan
Courses Plus Student 1,117 PointsIn the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but
In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. Use string interpolation to return the remainder inside the sentence “The remainder of a divided by b is c.” where a is your “a” variable, b is your “b” variable, and c is the value of a % b.
def mod(a, b)
c = "#{a}" % "#{b}"
return "#{c}"
end
mod(12,5)
1 Answer
Ari Misha
19,323 PointsHiya there! Outside of this challenge, your code might've been on point. But you've to stick to the challenge and instructions given. And your solution is outside the context of the challenge. The solution is pretty straightforward. You just have to return a string using string interpolation in the given function. Here is my code for reference:
def mod(a, b)
"The remainder of #{a} divided by #{b} is #{a % b}"
end
Nadia Masiero
3,468 PointsOh! That makes more sense! How does it recognize #{a % b} as being "c"?
Ari Misha
19,323 PointsNadia Masiero Think it this way! Lets just say , you stored the value of a % b in c variable and then you used the c variable instead of a % b in the above code. Its gonna render the same thing, isnt it? Also , for the best practices, you dont have to type "return" keyword 'coz Ruby does an implicit return behind the scenes. Like in your code, last line in the function will be returned by Ruby anyway, its a default. (:
~ Ari
Mubeen khan
Courses Plus Student 1,117 PointsThanks Friend....
Nadia Masiero
3,468 PointsAri Misha Okay, makes sense! Thank you!! ?
Nadia Masiero
3,468 PointsNadia Masiero
3,468 PointsI'm stuck on this too actually. I'm not entirely sure how to properly add the third variable "c"