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

Kazhian Muthusami
Kazhian Muthusami
2,484 Points

What is wrong with this code?

Why is this code not accepted?

method.rb
def mod(a, b)
 β€œThe remainder of #{a} divided by #{b} is #{c}.”
end

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Kazhian,

There are a couple things wrong here.

  1. First and foremost, your method doesn't return anything at all! You need to use a return statement.
  2. You're using curly quotes, or "smart quotes" instead of the unstyled quotes ". Not sure how that happened - did you copy-paste from somewhere?
  3. c is not defined.

I don't want to give you the solution, since I'm pretty sure you can figure it out from here. Let us know if you have trouble!

Cheers :beers:

-Greg

Kazhian Muthusami
Kazhian Muthusami
2,484 Points

Hi Greg, thanks for the reply. In ruby, return statement is not required. That's why I didn't include. However, now I added. But getting below error:

Bummer! The mod method could not be found.

Heres is the code:

def mod(a, b)
 return "The remainder of #{a} divided by #{b} is #{a%c}."
end
Greg Kaleka
Greg Kaleka
39,021 Points

Ah - you're right. Sorry, my Ruby is a bit rusty.

Looks like you fixed item 2, but item 3 still stands - you're using c, which is not defined. Switch that to b and you should be good.