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 trialMelodie Joseph
2,355 PointsNot sure what I'm doing wrong...
I'm not sure what exactly I'm doing wring, but it's probably to do with the end of my string...any suggestions?
def mod(a, b)
puts "The remainder of #{a} divided by #{b} is 'a % b'"
return a % b
end
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Melodie,
You're on the right track, but there are a couple of things:
You'll need to do the calculation for
a % b
before the string and store it in a variable calledc
.The challenge is asking you to
return
the string, but you are usingputs
.There is no purpose of the last return statement.
Below is the correct code for your reference. Have a look, and I hope it'll make sense.
def mod(a, b)
c = a % b
return "The remainder of #{a} divided by #{b} is #{c}."
end
Melodie Joseph
2,355 PointsThank you! Worked like a charm! :)
Tim Knight
28,888 PointsMelodie,
You want to make sure to actually run the calculation between a and b. Try something like this:
def mod(a, b)
"The remainder of #{a} divided by #{b} is #{a % b}."
end
One of the benefits of Ruby is that the last line by default will be returned so you don't have to specify a return value.
Jason Anders
Treehouse Moderator 145,860 PointsHey Tim.
Guess you type a bit faster. Lol. But, you're missing the period... and we all know how picky the challenges are.
Tim Knight
28,888 PointsYou're right Jason, I've made that slight modification to make sure to remove any chance for error. Thanks for that catch.
Melodie Joseph
2,355 PointsThank you both, both work. :)
Melodie Joseph
2,355 PointsMelodie Joseph
2,355 PointsThis is the question: 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.