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

John Wise
John Wise
1,128 Points

Problem with embedding return in interpolated string

Hello

I'm unable to complete the Method returns part 2 as I can't seem to embed the remainder return in a string. The task calls for only two arguments(a, b) so I'm unsure if I'm assigning a "c" value erroneously. I don't know exactly where the problem lies in my code.

best regards John

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

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey John,

There are a couple of issues here:

  1. The challenge wants you to return the string, but you are using puts.

  2. The challenge didn't ask to return the equation, so that line needs to go. (You could assign the calculation to the variable c c = a % b, but the line would need to be above the interpolated string. If it's below, the string has no idea those variables exist. However, this isn't how the challenge is worded, and the challenges are very picky and strict.)

  3. The calculation needs to be done inside of the interpolated string.

Below is the corrected code for you to review. If it's still not quite clear, I do recommend a quick review of the previous video, as interpolation and equations become a bit more prominent in future lessons.

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

Keep Coding! :dizzy:

John Wise
John Wise
1,128 Points

Thank you so much Jason. That helped.