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

Brian Patterson
Brian Patterson
19,588 Points

Not sure why I am getting a syntax error.

def mod(a, b)
  #write your code here
  puts  β€œThe remainder of #{a} divided by #{b} is c.”
  return a % b  
end

Not sure why I am getting a syntax error?

2 Answers

Hi Brian,

It wants you to return the string, not puts it. So, you use string interpolation for a, b and c.

Something like:

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

I hope that helps,

Steve.

Indeed, you don't need to use c at all, you can interpolate the result of the mod operator:

return "The remainder of #{a} divided by #{b} is #{a % b}."
Brian Patterson
Brian Patterson
19,588 Points

Thank you for your reply.

No problem, Brian. Glad you got it fixed. :-)

Steve.

You are very close but the challenge is looking for the string to be returned. First we have to declare c to be the remainder of a modulo b Second we return our string with all the variables inserted.

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