Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Julia Thalita Da Silva Carrilo
Julia Thalita Da Silva Carrilo
1,347 Points

When go run methods show syntax error!

This is my code:

def add(a, b) puts "Adding #{a} and #{b}:" puts a + b end

add(2, 3) add (5, 5) add (6, 6)

This is the error:

treehouse:~/workspace$ ruby methods.rb
methods.rb:7: syntax error, unexpected ',', expecting ')'
add (5, 5)
^

3 Answers

this should work just the way you want , i which i could explain it to you in the perfect workds but i am not a teacher. but hope you understand. you need to have a place holder.

def add(a, b) puts "Adding #{a} and #{b}:" puts c = a + b end

add(2,3) add(5,5) add(6,6)

Julia Thalita Da Silva Carrilo
Julia Thalita Da Silva Carrilo
1,347 Points

Didnt work.

treehouse:~/workspace$ ruby methods.rb
methods.rb:5: syntax error, unexpected tIDENTIFIER, exp ecting end-of-input
add(2,3) add(5,5) add(6,6)
^

you have a result like this: ubuntu@ubuntu:~/community$ ruby add.rb Adding 2 and 3: 5 Adding 5 and 5: 10 Adding 6 and 6: 12 ubuntu@ubuntu:~/community$

Make sure the "puts" are on different lines . its very important ***** puts "Adding #{a} and #{b}:" ***** ***** puts c = a + b ******

Julia Thalita Da Silva Carrilo
Julia Thalita Da Silva Carrilo
1,347 Points

I did.. sounds like a problem with treehouse.. so I'm stock!