Defining 2 Methods

Please help. There was no clear example of this code.

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.

This is my code below:

def greeter(name)
return “Hello”
end

def by_three?(number)
if number % 3 == 0
return true
if !(number % 3 == 0)
return false
end

Hi this part

if !(number % 3 == 0)
return false
end

Why dont you use a else statement like that

else 
    return false 

And you should add a end to close the Method by_three?

1 Like

the first part of the code is not working. How do you add a greeter code again?

The greeter should be like that


def greeter(name)
return "Hello" + name 
end

And then you should call greeter like that

greeter("type your name here")

1 Like

thank you. the notes didn’t give an example like this.

def by_three?(number)
(number % 3).zero?
end