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 trial

Ruby Ruby Basics (Retired) Ruby Methods Method Returns: Part 2

Why am I getting the message: Bummer! Make sure you return a nicely formatted string? (Challenge Task 1 of 1)

Challenge Task: In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. 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.

The error I got when submitting my answer: "Bummer! Make sure you return a nicely formatted string"

Given code:

def mod(a, b) # insert code here end

What I coded:

def mod(a, b) puts "The remainder of #{a} divided by #{b} is #{a%b}." end

mod(9, 5)

I wanted to add that I tested this in my workspace and it gave me the correct output:

def remain(a, b) puts "The remainder of #{a} divided by #{b} is #{a%b}" end

remain(7, 2) remain(5, 3) remain(6, 5)

treehouse:~/workspace$ ruby methods.rb
The remainder of 7 divided by 2 is 1
The remainder of 5 divided by 3 is 2
The remainder of 6 divided by 5 is 1

3 Answers

Jake Adams
Jake Adams
1,608 Points

This seems crazy to me, but if you change the puts to return, it passes fine. You also need to include a period at the end of the sentence.

def mod(a, b) return "The remainder of #{a} divided by #{b} is #{a%b}." end

Thanks Jake! That worked! (Changed 'puts' to 'return', plus adding 'puts' before 'mod(9, 5)' since I'm using return in the method. Yeah, I think it's a problem with this challenge because I just did a search on "nicely" and found two others with the same bummer message and a person on staff at Treehouse responded with the same code I originally used as working to pass the challenge...

Bradley Webb
Bradley Webb
2,577 Points

Just ran into this myself; thanks for the tip Jake. I think the test code for this challenge needs to be rewritten.