8/19 help

def greeter(greeting, *nombre)
nombre.each { |name| puts “#{greeting}, #{name}” }

def by_three?(number)
(number%3)?(return true): (return false)
greeter(“hello”, “sir”, “madam”)

“Oops, try again. It looks like your greeter method doesn’t include the person’s name in its output.”
Could someone help me?

You’re not doing what the instructions ask of you:

Define two methods in the editor:

  • A greeter method that takes a single string parameter, name, and returns a string greeting that person. (Make sure to use return and don’t use print or puts.)
  • A by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and false if not.
1 Like

def greeter(name)
return ‘Helo’*name
def by_three?(number)
return true
if number % 3 == 0
return false

1 Like

Why does it require *name on line 2? Any other syntax and the console returns an error.

1 Like

Could you pls tell me why there are double “end” at bottom of code?

One is to end the if statement, the other is to end the def.

wait, why does * work but + doesn’t? I’m confused please clarify

also when I call the method to test the greeter() it says an error when I put a actual name

Oh, that make sense, thanks.

The splat argument it better suited for applying your method to a variable without a static value. User inputted arrays are a good example. If ‘name’ only had one value then you could use a defined variable but this snippet doesn’t have one. Using the splat method is like telling your script “Stand by, I’ll have something for you to apply this to eventually.”

When you’re returning the name, there are not supposed to be any variables to label a name, this is purely proof of concept. If you were using this in your own interpreter, it would return nothing because this is just a method, it isn’t being applied to anything just yet. You would have to apply an array or hash ‘name’ variable to it.

If you were to tell your code to accept an established method or variable to use it would tell you that keyword doesn’t exist, whereas adding * makes it an argument, to apply IF there is a variable(s) for the greeter method to use.