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

Shawn Wilson
seal-mask
.a{fill-rule:evenodd;}techdegree
Shawn Wilson
iOS Development Techdegree Student 7,049 Points

CODE CHALLENGE: Create a method called "add" that takes two arguments and returns the sum of two numbers. -- Help pls.

hey all.. so this is from the Ruby Basics course and i'm stumped. my code matches what we did in the previous lesson, I've tried a few different things but for some reason it keeps returning: Check your Work error.

this is what i have:

def add (a, b)
  puts "adding #{a} + #{b}: "
  return a+b
end

puts add (3, 3)
puts add (5, 5)

I've even tried:

return add (3, 3)
return add (5, 5)

I've tried removing the puts statement in the method. to no avail..

all help is appreciated. answer not expected even just an explanation of where i am going wrong would help.

thanks!

2 Answers

Vrund Patel
Vrund Patel
11,994 Points

You don't have to return it. Just print.

puts ( " adding #{a} + #{b}:  ")
puts (a + b) 
Vrund Patel
Vrund Patel
11,994 Points

Return just returns the value and does not print to the screen. You need to print the answer so that it prints the answer to the screen. Hope this helps!

Shawn Wilson
seal-mask
.a{fill-rule:evenodd;}techdegree
Shawn Wilson
iOS Development Techdegree Student 7,049 Points

So I would want to use:

so then would

Puts return add (3, 3)

be what I'm looking for? Not sure why this is wracking my brain as hard as it is. Is my issue in the method its self of in the arguments below it?

In the lesson video it shows:

Puts add ( 3, 5)

Perhaps I'm just way over thinking this.