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

'Make sure you return a nicely formatted string' with instructions that would flunk a third grade writing test.

YOU HAVE GOT TO BE KIDDING ME!! This is the 'direction' and I use the term loosely. : In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. Use string interpolation to return the remainder inside the sentence “The remainder of a divided by b is c.” where a is your “a” variable, b is your “b” variable, and c is the value of a % b. I did this and received this message, 'Make sure you return a nicely formatted string'. WHERE are the instructions in this lesson for writing a 'nicely formatted string'. This is an overly wordy and prime example of the worst use of punctuation known to man. I'm so frustrated with these 'Challenge Tasks' that (a) make no sense (b) are poorly written and (c) do not reflect information that as 'Challenge Tasks' should actually BE IN the lesson.

method.rb
def mod(a, b)
  #The remainder of a divided by b is c.Where a is your "a" variable, b is your "b" variable,and c is the value of a % b.
end
Katie Boster
Katie Boster
1,606 Points

I completely agree. I had trouble with this one as well and I felt the steps within the lesson leading up to this challenge did not fully support the challenge.

Katie Boster & Sarah Augustine I also agree, the difficulty level shot up significantly and suddenly with this one. There needed to be at least 1 intermediate code challenge before this one. I gave it my best try but the error message doesn't give an actual message but a huge Syntax error.

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

15 Answers

Amy Kang
Amy Kang
17,188 Points

I don't think I ever did this course but it seems they want you to save the result of a % b in c variable and put that in a sentence. Something like this:

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

Edit: It should work now.

Pedro Henrique Knoll Giacometo
Pedro Henrique Knoll Giacometo
6,669 Points

Add return before the string " ".

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

Ok. Thanks. I'll try that. May I ask, how did you glean that's what you were supposed to write? I'm guessing your answer was based upon experience, not so much the instructions that were given...

Amy Kang
Amy Kang
17,188 Points

I guess I knew the answer because I already know about variables and string interpolation. I learned Ruby on Codecademy, worked through Well-Grounded Rubyist, and practiced on Code Wars and Ruby Monk. Those sources may help you if you want to learn more Ruby.

Josh Karp
Josh Karp
12,651 Points

They're looking for the following format:

return "The remainder of #{a} divided by #{b} is #{c}."

Amy Kang
Amy Kang
17,188 Points

In ruby you don't have to write an explicit "return" if you're returning the last value.

Thank you, it worked!!

I was typing this which didnt work.

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

and the correct one is

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

Thanks for trying. : ) That was a nice thought, Amy. But no, that's not the answer the instructor is looking for.

Amy Kang
Amy Kang
17,188 Points

Hi I just tried the challenge and it passes but I had to type it in. It failed when I copy pasted it.

It worked for me as well

why wouldnt we put "puts" in front of the sentence?

Amy Kang
Amy Kang
17,188 Points

The challenge asks you to return a string. "puts" is printing out the string.

Everybody forgots dot :) Dot is the problem at the end of the sentence ;)

William Timmons
William Timmons
4,975 Points

Please be sure to put the period at the end of the sentence! It won't allow you to pass without the proper punctuation in the sentence, just like they provide you. The code will work if you write it correctly, but the period at the end is needed to pass the challenge!

Martina Reiter
Martina Reiter
17,654 Points

Dunno if it helps but i copy pasted the sentence and i had errors because the double brackets were not the right double brackets :/

Grant Wilson
Grant Wilson
2,171 Points

LOL! Defeated by a DOT! Yup... Period is key.

Winston Quin
Winston Quin
10,359 Points

Treehouse does seem to have challenges that are either too easy to be challenging or are just unclear in their meaning. It does seem like programming in general is full of stuff like that, though.

I didn't see your earlier reply, ' I already know about variables and string interpolation. I learned Ruby on ...' Thanks so much for sharing. I'll be sure to look up Codecademy, Code Wars and Ruby Monk. I appreciate the information!

Bryan Andrews
Bryan Andrews
1,322 Points

I just took the challenge, and I kept failing even though my code was exactly the answer posted above. Know what failed me? A missing period after the #{c}. Sloppy, I know, but it shouldn't have been fail-worthy. The code worked.