Ruby Ruby Basics Ruby Syntax Method Arguments

say.rb - I don't know what I'm doing wrong

Instructions: Define a method named say. say should take one parameter (name the parameter whatever you want). In the say method body, take the parameter and pass it to puts as an argument. End your program with a call to the say method, and pass the string "Ruby" as an argument.

I've tried so many variations and Google'ing I can't figure out how to fix this error:

Bummer! Your "say" method should take exactly 1 parameter.

def say

puts "Ruby"

end

say

3 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! The challenge asks you to define a function that takes one parameter. Currently, your function takes no parameters. Then the function should use puts to put whatever you send in to the screen. However, your code will always print out "Ruby". We want this to be more flexible. We want to print out whatever was sent in.

def say(greeting)
    puts greeting
end

say("Hi there, Ari!")

In the example above I declared a function named "say" that has one parameter. When I call this function a piece of information will be passed in. I'm sending in the string "Hi there, Ari!". This will be assigned to a local variable named greeting. I then print the value of greeting to the screen.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

This makes sooooo much more sense. THANK YOU!

I'm having problems with this challenge too and what you say still makes no sense I even tried to copy what you did and change things to how I thought it should be and still I get errors

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Brent Rainwater It's impossible to help you without seeing what you're trying. I would, however, be interested to know what I've written "makes no sense". You might be better served to post a new question on the forums where a student more knowledgeable or helpful than myself can assist you :sparkles:

def say name
  puts "Ruby"
end

say ("Ruby")

this is what I'm working on. I have tried everything I know how to do and still nothing. Ive even watched the videos twice and it seems as if Im doing things right but still get errors

Moderator edited: added markdown to the post so that code renders properly in the forums.

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

You're really close, here! Also, I meant to post a new question to the forum instead of an answer to this question. But for now, I'm willing to answer here. First, your code lacks a pair of parentheses around the name parameter. Also, your code will also always print out "Ruby". What if we wanted it to print out "Java" instead? We want this to print out whatever we tell it to print out from the call site. The "call site" is the last line. It's the line that says to execute the function with this piece of information being sent in:

def say(name)  #note the parentheses here, whatever is sent in will be assigned to the variable name
    puts name    #print out the value of the variable name
end

say("Brent")  #call the function and send in "Brent". When the function runs, the variable name will have the value "Brent" and that is what is displayed.

Hope this helps! :sparkles:

it did - Thank you - Thank you very much!!!

Nadia Masiero
Nadia Masiero
3,468 Points

I'm having the same problem too. Could you brief me on how you figured this out? The error, Bummer: We couldn't find a method named "say". Did you define one?

say.rb
def say (Ruby)
  puts Ruby
end
say ("Ruby")