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

Bryan Sory
Bryan Sory
1,978 Points

how to format string in modulo question

it says it's formatted incorrectly but like to see others'

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

2 Answers

Rogier Nitschelm
seal-mask
.a{fill-rule:evenodd;}techdegree
Rogier Nitschelm
iOS Development Techdegree Student 5,461 Points

This might be due to the two 'a''s you have in your string. Also the .to_s-method is outside of the curly braces, which means it will just be printed, rather than executed on your ruby-code. Also I believe you do not need .to_s because the code itself is already printed as a string.

Perhaps something like this?

def mod(a, b)
  puts "The remainder of #{a} divided by #{b} is #{a % b}"
end
Mike Hickman
Mike Hickman
19,817 Points

Hi Bryan,

Rogier provided good solution code. The main problem in your code is that #{mod} is the only thing being interpolated. The .to_s will literally be printed as text at the end of your puts statement just like the rest of the text before #{mod}.

Cheers,

Mike