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 trialJames Hyland
Courses Plus Student 8,607 PointsQuestion in reference to "Method Returns: Part 2 Objective 1"
I entered the following code: def mod(a, b) puts "The remainder of #{a} divided by #{b} is: " return a % b end
puts mod(5, 3)
I receive the following notification: Bummer! Make sure you're returning a string from the mod method.
I know this code works, I created a file and ran it through my console and the output is: The remainder of 5 divided by 3 is: 2
def mod(a, b)
puts "The remainder of #{a} divided by #{b} is: "
return a % b
end
puts mod(5, 3)
2 Answers
andren
28,558 PointsYour code prints the string and then returns a number, and while that might look fine in the Ruby REPL it is not in fact what the challenge is asking for. It is asking you to return the string itself, not to print it.
So the return
statement should be placed before the string, you should also include the a % b
part within the string itself. Like this:
def mod(a, b)
return "The remainder of #{a} divided by #{b} is: #{a % b} "
end
James Hyland
Courses Plus Student 8,607 PointsThank you, that makes sense. I misinterpreted the challenge.