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

I am not sure why my code isn't working

I am on basic ruby methods and I reviewed the syntax many times, but my code still isn't working. Why?

method.rb
c = a % b

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

mod(3, 1)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're pretty close on this one. Here's my code and I'll walk you through it!

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

At first, you declare a variable c and set it as the mod of a and b. However, a and b aren't defined until they reach your function. They are outside of the "scope" of the function. So, we move that line down inside the function. Secondly it wants a return statement... not a puts.

oh thanks soo very much