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 trialRyan Christy
iOS Development Techdegree Student 4,543 PointsCode Challenge: Method Returns: Part 2
Hi,
What is the challenge asking when it says to make sure the string is formatted nicely?
I have a code that works perfectly but it still says Bummer.
Thank you!
def mod(a, b)
return a % b
puts "The remainder of #{a} divided by #{b} is #{mod(a, b)}."
end
a = 15
b = 4
mod(a, b)
1 Answer
andren
28,558 PointsOnce a function returns a value it stops executing. In other words everything after the return line is completely ignored and never ran. On top of that this challenge want the function to return the string, not the value of a % b
.
It's also worth noting that if you had placed the puts
line above the return
line then you would end up with an infinite recursive loop since your function calls itself which results in it calling itself again and then again and so on.
If you actually return
the string and just use the a % b
equation directly for the c
placeholder like this:
def mod(a, b)
return "The remainder of #{a} divided by #{b} is #{a % b}."
end
Then your code will work.
Ryan Christy
iOS Development Techdegree Student 4,543 PointsRyan Christy
iOS Development Techdegree Student 4,543 PointsThank u !