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
Lyric Abbott
35,595 PointsNeed 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
Michael Hulet
47,913 PointsYou'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
notf0und
11,940 PointsThe % 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.
Lyric Abbott
35,595 PointsLyric Abbott
35,595 Pointsit didnt work
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsActually, 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