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

YI JIANG
YI JIANG
3,424 Points

what's wrong

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

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

2 Answers

You are very close but missing some interpolation.

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

puts mod(5, 2)

-- I used the above example to check the code since 5 % 2 = 1 and got back "The remainder of 5 divided by 2 is 1"

I didn't check the challenge but I think there needed to be a period at the end of the output.

YI JIANG
YI JIANG
3,424 Points

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

puts mod(5, 2)

not working why puts?

You don't need to call the function. you only need to write the function definition.

As woodworth mentioned, you're still missing the interpolation for a

Also, it's not going to pass without a period at the end of the string.

You are still missing #{ } on the letter a before divided.

I did this problem in my console so used puts to check to see if it worked with the two numbers knowing 5 % 2 = 1. I then got back "The remainder of 5 divided by 2 is 1"

Via Jason, it doesn't sound like you need to call the function for this exercise though so you can ignore that part of the code (but will still need to add a period to the end of the sentence).