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 trialUnsubscribed User
7,386 Points'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.
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
A X
12,842 PointsKatie 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
17,188 PointsI 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
6,669 PointsAdd return before the string " ".
def mod(a, b)
c = a % b
return "The remainder of #{a} divided by #{b} is #{c}."
end
Unsubscribed User
7,386 PointsOk. 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
17,188 PointsI 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
12,651 PointsThey're looking for the following format:
return "The remainder of #{a} divided by #{b} is #{c}."
Amy Kang
17,188 PointsIn ruby you don't have to write an explicit "return" if you're returning the last value.
Bridge Kode
2,959 PointsThank 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
Unsubscribed User
7,386 PointsThanks for trying. : ) That was a nice thought, Amy. But no, that's not the answer the instructor is looking for.
Amy Kang
17,188 PointsHi I just tried the challenge and it passes but I had to type it in. It failed when I copy pasted it.
Steven Islas
691 PointsIt worked for me as well
kennethbartlett
2,127 Pointswhy wouldnt we put "puts" in front of the sentence?
Amy Kang
17,188 PointsThe challenge asks you to return a string. "puts" is printing out the string.
Ivan Kusakovic
12,197 PointsEverybody forgots dot :) Dot is the problem at the end of the sentence ;)
William Timmons
4,975 PointsPlease 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
17,654 PointsDunno 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
2,171 PointsLOL! Defeated by a DOT! Yup... Period is key.
Learning coding
Front End Web Development Techdegree Student 9,937 PointsThe given code works. But what does it mean in plain English? I am lost at this point. More explanation would be appreciated! :)
Winston Quin
10,359 PointsTreehouse 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.
Unsubscribed User
7,386 PointsI 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
1,322 PointsI 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.
Katie Boster
1,606 PointsKatie Boster
1,606 PointsI 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.