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

Carolyn Buck
Carolyn Buck
4,067 Points

when i put this into workspace consule it works WTF?

the code works in the workspaces and prints out the correct stuff but it says im not formatting it correctly?

method.rb
def mod(a, b)

  puts "The remainder of the divided by #{b} is #{a % b}."
  return a % b
end

mod(2, 3)

2 Answers

The challenge is expecting you to return the string rather than putting it in the console.

Instead of puts, just return the string. Make sure to double check the format for the string.

Piotr Misiopecki
PLUS
Piotr Misiopecki
Courses Plus Student 10,421 Points

Try this:

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

Ruby has implicit returns so the string variable in your answer is unnecessary here Pitor. You could refactor this to be much neater like this ->

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