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

melisa pettaway
melisa pettaway
9,556 Points

ruby basics methods

having issues on the remainder code challenge. i have put in #{a} #{b} #{c} but it keeps saying my punctuation is wrong. tried it in workspace and it gave me the correct value. i am not quite sure what im doing wrong.

3 Answers

It should look something like this:

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

One thing to note David is that it's more idiomatic Ruby to not state a return—Ruby automatically returns the last value within the method.

Tim Knight
Tim Knight
28,888 Points

Melisa,

Make sure you have a period on your sentence, that sometimes causes a failure. Basically it should look like:

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

or you could leave out the c variable with:

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

thanks everybody! i forgot the period at the end. lmbo!!!