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 trialHenry Dashwood
Courses Plus Student 4,336 PointsCould someone explain where I am going wrong on this method question?
My code is attached. I'm struggling to to get a, b and c to be recognised in the sentence.
def mod(a, b)
c = a % b
return c
puts "The remainder of {a} divided by {b} is {c}"
end
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Henry,
Sorry no one got to you sooner.
There are a few things going wrong with the code you have. One a syntax error and three that either the challenge didn't ask for but you added or the challenge asked for and is missing. Challenges are very picky and very specific in the instructions.
First, the challenge didn't ask for a return statement for the c
value, so the return c
just needs to be deleted. Second, the challenge wants the sentence returned, and you are using puts
. Third, the sentence needs to end in a period, so just add one for the challenge.
And the syntax error. When interpolating variables in strings, you need to prefix the {} with a pound sign, so it looks like #{variable}
The corrected code is below for you. Have a look, and I hope it makes sense.
def mod(a, b)
c = a % b
return "The remainder of #{a} divided by #{b} is #{c}."
end
Henry Dashwood
Courses Plus Student 4,336 PointsThank you. Much appreciated!