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 trialLeonardo Escalante
3,190 PointsWould you please to give more information about interpolation in ruby, I couldn't resolve the code challenge.
def mod(a, b)
puts "The remainder of #{a} divided by #{b} is #{c}"
c = a%b
end
mod (8, 3)
mod (6, 2)
mod (10, 3)
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi Leonardo,
You've pretty much got it, but if you wanted to do it this way, you would need to declare the c
variable before the output of the sentence.
However, the code challenges are very picky and strict, and this is not the way it wants it done. First, the challenge wants you to return
the sentence (you have puts
). Second, the challenge wants you to "return the remainder inside the sentence" (note the keyword 'inside'). Therefore, you cannot create a c
variable to do the math... it must be done inside the sentence. Third, there is a missing period at the end of the sentence.
So, although your coded sentence is valid, this is what the challenge is looking for:
def mod(a, b)
return "The remainder of #{a} divided by #{b} is #{a % b}."
end
Keep Coding! :)
Leonardo Escalante
3,190 PointsThank you very much, i couldn't have resolve it if you didn't help me !
Jason Anders
Treehouse Moderator 145,860 PointsYou're welcome.
If you could mark it "Best Answer" as this is the way to let others in the community know that your question has been successfully resolved. :)
Enjoy the rest of the Ruby course.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThe code challenge will accept the use of the
c
variable but it does need to come before the output as you mentioned.Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsThanks Jason,
I didn't even try using the variable just because of the way the question was worded, and I was sure I remember getting a bummer (back when I did this course) when I tried the variable thing.
Anyways, good to know that it can be either/or for this challenge. Thanks. :)