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

How should my sentence be formated?

I get bummer on my code because it is not formatted correctly. It seems to me that the sentence comes out like it should. What am I doing wrong?

method.rb
def mod(a, b)
  puts "The remainder of #{a} divded by #{b} is "
  return a % b
end

puts mod(9, 4)

1 Answer

Stephen Beckstrand
Stephen Beckstrand
11,169 Points

Right now, your code is returning two lines, and not a complete sentence:

The remainder of 9 divded by 4 is
1

You want to have it all returned as one line as a complete sentence. Do something like this:

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

or

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

Also, It helps to be able to review the existing questions and documentation to answer questions. When going to the discussion page for this challenge, you can see that several others have asked similar questions and received answers:

All discussions:

https://teamtreehouse.com/community/code-challenge:2182

Few that could have helped you:

https://teamtreehouse.com/community/returning-strings

https://teamtreehouse.com/community/could-someone-explain-where-i-am-going-wrong-on-this-method-question

Thanks for such clear explanations. This was definitely a duh moment for me. I greatly appreciate the resources as well.