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 Ruby Basics (Retired) Ruby Methods Method Arguments: Part 1

Having trouble with "Create a method called "hello" that takes one argument." in Ruby

I am having trouble with my code on "Create a method called "hello" that takes one argument." in the Ruby Challenge Task 1 of 1. What is wrong with my code?

method.rb
def hello(a, b)
  puts a + b
end

add(4, 5)

2 Answers

Your function takes two arguments - a and b. To change it to a hello() function that greets someone, it should look more like this:

def hello(name)
  puts "Hello " + name
end

You also are calling a different function add() that takes two arguments. Instead, you should be calling hello(), passing a single argument, e.g.:

hello("Mark")

Hi Mark,

I think your method has two arguments. and you did not define 'add' method before using 'add' method.

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

add(4, 5)