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

Confusion with question-How to I show the variable 'c' in the string?

I am completely confused by how I am supposed to incorporate the value 'c' (a % b) into this string. I have re-watched the lesson to see what I missed and think I'm just not grasping the concept behind it. If anyone can explain to me what the question is asking and how to resolve this I'd appreciate it! Thanks.

Here is the code I have entered:

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

I just tweaked your code to add syntax highlighting. :)

1 Answer

Seth Reece
Seth Reece
32,867 Points

Hi Doug,

You are pretty close. First, you want you method to return a string, not print to standard output. Second, when interpolating a string, you have to use variables inside your variable placeholders. You would want to declare a variable c = a % b. e.g.

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

Thanks!