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

Would you please to give more information about interpolation in ruby, I couldn't resolve the code challenge.

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

mod (8, 3)
mod (6, 2)
mod (10, 3)

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Leonardo,

You've pretty much got it, but if you wanted to do it this way, you would need to declare the c variable before the output of the sentence.

However, the code challenges are very picky and strict, and this is not the way it wants it done. First, the challenge wants you to return the sentence (you have puts). Second, the challenge wants you to "return the remainder inside the sentence" (note the keyword 'inside'). Therefore, you cannot create a c variable to do the math... it must be done inside the sentence. Third, there is a missing period at the end of the sentence.

So, although your coded sentence is valid, this is what the challenge is looking for:

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

Keep Coding! :)

The code challenge will accept the use of the c variable but it does need to come before the output as you mentioned.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Thanks Jason,

I didn't even try using the variable just because of the way the question was worded, and I was sure I remember getting a bummer (back when I did this course) when I tried the variable thing.

Anyways, good to know that it can be either/or for this challenge. Thanks. :)

Thank you very much, i couldn't have resolve it if you didn't help me !

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

You're welcome.

If you could mark it "Best Answer" as this is the way to let others in the community know that your question has been successfully resolved. :)

Enjoy the rest of the Ruby course.