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

Carmine Lentini
Carmine Lentini
4,449 Points

Return in a string

I tried in a lot of ways, but i can't find the rigth way to resolve it, where im wronging?

Carmine Lentini
Carmine Lentini
4,449 Points

def mod(a, b) #write your code here

puts "The reminder of #{a} divided by #{b} is #{c}" return a % b end

puts mod(9, 2)

6 Answers

Remainder is misspelled.

You need to first assign the solution of the modulus operator to the variable "c". Then return the string with "a", "b" and "c" interpolated.

Here is what I would do:

def mod(a, b)
     c = a % b

     return "The remainder of #{a} divided by #{b} is #{c}."
end

Fill in the string with the correct interpolation and you should be fine. I didn't want to give away the complete answer.

Carmine Lentini
Carmine Lentini
4,449 Points

Hello, thank you for the answer, i did try to write this code several times, but the site give to me the following answer: Something doesn't look quite right. Double check your spelling and punctuation.

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

end

mod(9,2)

Try is without calling the method mod(9,2). That's extra code that you don't need.

Carmine Lentini
Carmine Lentini
4,449 Points

I don't know where i'm wrong but i think it is correct!

def mod(a, b) 
  #write your code here
  c = a % b
  return "The reminder of #{a} divided by #{b} is #{c}."
end
Carmine Lentini
Carmine Lentini
4,449 Points

I can't believe that i wrote Remainder in a wrong way and i didn't pay attention to it. now it's work, thank you so much for the help, and shame of me ahah .