Bummer! You must be logged in to access this page.

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

Need help with Ruby methods

Create a method called "add" that takes two arguments and returns the sum of two numbers.

http://teamtreehouse.com/library/ruby-basics/ruby-methods/method-returns-part-1

my code:

def add (a, b)
  puts a + b
end

add (2, 3)

ruby methods.rb - returns error

2 Answers

You're being asked to return the sum of 2 numbers, not log it to the console, so you don't need the puts statement. This code should do:

def add(a, b)
  a + b
end

it didnt work

Actually, looking at the code challenge this time, you don't need to call the method to pass the challenge. I've updated the code I gave you to reflect this. Copy and paste it again, and it should definitely work this time

The % operator does not return the sum of two numbers. You'll want to use the + sign. Your function name is also not what the Code Challenge is asking for.

http://www.tutorialspoint.com/ruby/ruby_operators.htm