8/19 help


#1

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

def by_three?(number)
(number%3)?(return true): (return false)
end
greeter("hello", "sir", "madam")
by_three?(12)

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


#2

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.

#3

def greeter(name)
return 'Helo'*name
end
def by_three?(number)
return true
if number % 3 == 0
else
return false
end
end


#4

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


#5

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


#6

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


#7

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


#8

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


#9

Oh, that make sense, thanks.


#10

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.


#11

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.