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

Vivienne Kay
Vivienne Kay
1,708 Points

I'm not sure what else this challenge requires. How do I make sure the string is nicely formatted?

I'm not sure if I need to create the variable c here or not. It works fine when I do this in the console, so I have no idea what's wrong with this code. This is the challenge question "Use string interpolation to return the remainder inside the sentence “The remainder of a divided by b is c.” where a is your “a” variable, b is your “b” variable, and c is the value of a % b."

The error I keep getting is "Make sure you return a nicely formatted string."

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

puts mod(2, 6)

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

Well I haven't used any Ruby yet, but from what I can tell by reading your code, you aren't returning a string, you are returning a number. I don't know what puts does but I am assuming that it is some sort of printing to console/screen/browser, and right now that is not what the challenge is calling for, it is calling for you to return the string that you formatted above, but also include the answer in it. At least that is what I think, having not used Ruby before I just copied your method from earlier and used the same concept:

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

Congrats :+1:

You understood what puts meant! It prints stuff to the screen. It's short for "put string"'

Dane Parchment
Dane Parchment
Treehouse Moderator 11,077 Points

Ah, that's easy to remember put string. Thanks, maybe after my school semester dies down (so many programming and software engineering projects) I may take my time to learn some Ruby.

Vivienne Kay
Vivienne Kay
1,708 Points

Thank you SO much, it worked!