Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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