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

Tyler Martin
Tyler Martin
3,535 Points

Problem with Ruby Code Challenge

Create a method called "mod" that takes two arguments, "a" and "b", and returns the remainder of "a" when divided by "b". Hint: remember the "%" operator!

def mod(a,b)
  return a % b
end

mod (3,2)

This is what I did and it gives me an error. I feel like I'm missing something obvious here.

5 Answers

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

Hi Tyler,

You wouldn't want to put a space between the function name and the parentheses that wrap your parameters

i.e.

mod(3,2)

but not

mod (3,2)

Hope that helps!

def mod(a, b) return a % b end

Tyler Martin
Tyler Martin
3,535 Points

Thank you that did it!

Thx I needed help on this to I just had puts instead of return. How do we know the difference when asked to write a method?? Im good at everything all the syntax but when asked to do something im clueless the wording stumps me.

lina Hernandez
lina Hernandez
4,583 Points

def mod(a,b) return a % b end

mod (3,2)