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

Cassandra Jones
Cassandra Jones
7,113 Points

Ruby basics - The remainder of a divided by b is c.

I am having a hard time with this one. I found two other threads on this but neither resulted in a fix either. This is what I mocked up in workspaces:

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

puts mod(2, 3)

And it works, in workspaces. However it does not work in the code challenge. I have also tried:

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

end

puts mod(2, 3)

Even though these seem to work in reality, the code challenge won't accept them. (I am very new to this clearly.

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Cassandra,

You've pretty much got it. (The one with the "return" statement is what the challenge is looking for. You just have one function error and one punctuation error.

First, the punctuation. Challenges are very picky and very strict when it comes to what it wants. This one wants the sentence returned with a period at the end (which is missing in your code). I know... picky-picky. :)

Second, the challenge just wants you to call the function. It doesn't want anything done with it... so just delete the "puts."

Other than that, it all good. :)

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

mod(2, 3)

:dizzy:

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

I also added markdown to your post so the code is more readable. You can read more in the markdown cheatsheet at the bottom of the post page.

Also, when possible, it's best to click the "Get Help" button located on the quiz, challenge, or video screens, as this will link your question directly to where you are in a course (easier reference for us). Sometimes, that button doesn't work, so the way you did it this time is fine, but it should include then a link to the challenge.

Anyway... Welcome to Treehouse and Keep Coding! :smiley:

Cassandra Jones
Cassandra Jones
7,113 Points

The reason I did the "get help" the way I did was so I could reference my code challenge while writing the question. If I went directly from the challenge, the screen was locked and so I kept having to get out and make sure I had the right information. I am not sure if that is how it should be working but that was why. I will try doing it through the challenge next time. And again, thank you!

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

You're very welcome, and yeah, that's why I added the "sometimes it doesn't work" :)

They've been having issues with that feature these past couple weeks. All good. :)