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 trial

Ruby Ruby Basics (Retired) Ruby Methods Method Returns: Part 2

What is the answer here? For someone reason, I'm completely stumped on the proper syntax here.

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.

method.rb
def
  puts "The remainder of #{a} divided by #{b} is #{c}:"

end

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Kyle,

You're on the right track, but there are a few issues preventing the challenge from passing:

  1. First, for some reason you have deleted part of the code that was pre-loaded, specifically the method name and definition.
  2. You are trying to interpolate a value for c, but c is not defined anywhere. The question doesn't want you to create a new variable (although you could), but rather, the challenge wants you to do the calculation inside of the interpolation.
  3. You have a colon at the end of the sentence instead of a period (challenges are very picky).
  4. The challenge explicitly asks you to return the string, but you are using puts.

You will need to reset the challenge to get back the deleted code, and with these hints in mind, you should be able to pass the challenge.

Keep Coding! :) :dizzy:

Got it! Thanks for taking the time to explain it, I really appreciate it. I think looking at it with fresh eyes also helped my cause.

Tobias Jackson
Tobias Jackson
9,758 Points

I don't get it. Can some show how its look like?

Should look like this,...

def mod(a, b) c = a % b "The remainder of #{a} divided by #{b} is #{c}." end