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

Varun Khanna
Varun Khanna
1,831 Points

Cant figure out whats wrong

please help.. whats wrong with the code?

method.rb
def mod(a, b)
  #write your code here
  a = a 
  b = b
  c = a / b
  β€œThe remainder of a divided by b is #{c}.”
end

2 Answers

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

Hi there! You have a few problems. To begin with you do not need the a = a and b = b. Those are given when they come into the function. Also, the challenge explicitly asks you to return the string. But you're not doing anything at all with the string. It's not being printed or going to a variable.

The remainder of 7 divided by 3 would be 1. Because three goes into 7 twice with one left over. But you're assigning the result of division to the variable c. In my example, c would now be equal to 2.333....

And finally, you're using the wrong kind of quotation marks in your string. This will cause compiler errors. Take a look:

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

Here we define the function. We make a new variable named c. Then we assign the modulus of a and b to c. Then we return the string (with the correct quotation marks). Hope this helps! :sparkles:

Varun Khanna
Varun Khanna
1,831 Points

Thanks a ton for helping me out!