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

Method Returns Part 2

Hi, I'm completing this Task and it ask me to place the remainder as my value C from dividing value A by value B, I place this code

def mod(a, b) remainder = a%b return "The remainder of dividing a by b is: #{remainder}" end

puts mod(2, 2)

and it gives me this result : The remainder of dividing a by b is: 0

But When I try to check the work it gives me the error : Check your spelling and punctuation. Just wanting to know what is wrong with it?

Thanks you.

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

puts mod(2, 2)

1 Answer

Damien Watson
Damien Watson
27,419 Points

In your output, you need to also replace the values of 'a' and 'b'. Your wording is also not as expected. Try this way around:

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

puts mod(2, 2)

Appreciate it!

Damien Watson
Damien Watson
27,419 Points

If this is the correct answer, you can mark it. May help others find the right answer. Cheers.