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

ms onefaithlove
PLUS
ms onefaithlove
Courses Plus Student 2,794 Points

I have a feeling it's very obvious... pardon me! What am I doing wrong?

Which two arguments should be beside mod? How do I say a%b=c in a valid way?

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

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Ana,

You are on the right track, but there are 3 little things:

  1. You have an unneeded puts statement (that also wasn't asked for in the challenge) where you are doing the calculation. This calculation should actually be done right in the interpolated string.

  2. You are using puts on the interpolated string when the challenge is asking for a return.

  3. Challenges are very picky and very strict. So, this one is more just that. You are missing a period inside of the String Interpolation.

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

Keep Coding! :)

Kourosh Raeen
Kourosh Raeen
23,733 Points

The method should return that string so try return instead of puts:

def mod(a, b)
  c = a % b
  return "The remainder of #{a} divided by #{b} is #{c}."
end
ms onefaithlove
PLUS
ms onefaithlove
Courses Plus Student 2,794 Points

Thank you both!!! This makes so much sense. Sipping (gulping) a fresh cup of coffee. Need it evidently, ha! Brilliant.