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

Yuichi Narisawa
Yuichi Narisawa
19,548 Points

Ruby Basics Code Challenge

Hi, I’m newbie of coding, and I’ve stacked Ruby Basics Code Challenge.

In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. 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.

I wrote the following code, however, it returns “ArgumentError: wrong number of arguments (given 2, expected 3)"

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

I know it’s very basic, and I’m embarrassed to ask this easy question, but... please help me!

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

mod(1,2)

1 Answer

Hey Yuichi,

To start, you should not be modifying the parameters of the mod method. It should still only take two arguments, a and b. The challenge prompt is specific and will not accept anything different. Instead, c should be declared inside of the mod method and be assigned the remainder of a divided by b. Lastly, you'll want to return the required sentence using string interpolation.

Here is a correct solution:

def mod(a, b)
  #write your code here
  c = a % b
  return "The remainder of #{a} divided by #{b} is #{c}."
end
Yuichi Narisawa
Yuichi Narisawa
19,548 Points

Hi, Jacob!

Thank you so much for your advice! You made my day! ;)