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

not sure what I am doing wrong

I am trying to write this method but it seems like it is not working

method.rb
def mod(a, b)
  puts "The reminder of a divided by #{b} and c. " where a is your "#{a}" variable, b is your "b" variable and c is the value of a%b"
  c = a%b
  return c
end
mod(5,5)

2 Answers

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Yashoda,

there are a few mistakes in your code. You wrote "where a is your "#{a}" variable, b is your "b" variable and c is the value of a%b" in your method, however this is part of the challenge's instruction and should not be in your code, so please remove it.

A small problem is also that you have a typo and you write "reminder" instead of "remainder", you wrote "and" instead of "in" and that you have a space in the end of your string which shouldn't be there.

You should also interpolate the variables a and c in your string but you only interpolated b. In order to be able to interpolate c you have to assign the value of a % b to c before the string.

The last two problems are that you're returning the remainder but the challenge wants you to return the string and that you don't have to call the method yourself, this will be done automatically when the challenge is evaluated. :)

If you do all of this it should look like this:

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

Good luck! :)

Thank you