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 trialMark Miller
45,831 PointsStill, no way through this quiz, Method Returns: Part 2 (Ruby Basics)
Will someone please reveal the code for this quiz?
3 Answers
Gavin Ralston
28,770 PointsIn 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.
Okay, so... you're working with string interpolation, which just means replacing placeholders in your string with some other values you already have stored in variables (passed into your method, or created inside of it, in this case).
Here's an example that isn't exactly like what the challenge asks for, but is comparable and should make a good template for you to get your head around it:
def add(a, b)
c = a + b
"The sum of #{a} plus #{b} is #{c}."
end
In the example above, you're just plugging the values stored at a, b, and c, whatever they might be, right into the string by replacing them when you return the string from the method.
...and, since Ruby will return the last statement in a method automatically, that string will get returned. You can always add a return statement in front of the string if it's easier to read.
One specific "gotcha" on this challenge if you understood all that already is this: watch the punctuation in the challenge text -- There's a sneaky little "." character at the end of that sentence that I find hard to see with the current font weight in the challenges.
Stephen Toole
1,671 PointsThanks this was driving me crazy :D. Good tip about that period it's easy to miss. And i didn't know you needed to define c.
Gavin Ralston
28,770 PointsWell, you don't have to define c, you could just plug "a + b" into the last placeholder. :)
Stephen Toole
1,671 Pointsoh ok cool. yeah i was trying that at first but i think i was missing that last period when i was using a % b as placeholder.
Akin Soyleyen
3,579 PointsThat was keeping me awake for 2 days.
Neil Anuskiewicz
11,007 PointsNeil Anuskiewicz
11,007 PointsHi Mark, what quiz do you mean?