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

Tyler Proctor
Tyler Proctor
11,458 Points

Why is it telling me my string isn't formatted correctly? I've tried this in a number of ways.

I know the method was created properly because that was the challenge before this one, so the issue must be within the method itself. I've tried this multiple different ways and can't seem to get it correct. Does Ruby require you to initialize variables like in Java? Is c not being recognized as a variable?

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Tyler,

You're very close, just a couple of things.

  • The challenge wants you to return the string (you are using puts).
  • The challenge says nothing about returning just the value. This needs to be done inside of the string. Right now, your string is incomplete. It just reads "The remainder of a divided by b is" (is what?). It's also missing a period at the end (and yes, the challenges will often fail with missing punctuation).

I don't normally give answers outright, but you've pretty much got, so below is the correct code for you to review.

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

Keep Coding! :) :dizzy:

Tyler Proctor
Tyler Proctor
11,458 Points

Thank you so much! I figured it was due to some small oversight. I spent a way too much time checking, altering, and re-checking.