Stuck defining methods


i keep recieving
undefined local variable or method `n' for #

def greeter
  return "good morning, how are you today?"

def by_three?(n)
  return n % 3 == 0
  if n % 3 == 0
      by_three = true
if n == 0
    puts "#{n} is true!"
    puts "#{n} is false."

by_three (6)

I can't find the topic I posted to check the replies, help!

Your greeter funcion should take a parameter and return a string that says Hello,

def greeter(name)
    return "Hello #{name}!"

your function di not take any parameters,

The control flow of your by_three? function is all over the place :sweat_smile:, this line should not be the first line,

this one should,

and this,

should be,

return trueBecause you are returning true if the parameter is divisible by three.

finally this block,

can be written as one simple else statement that evaluates and returns false if the true condition is not met,

        return false


Thank you. I finally passed that lesson. Thanks again for the help.


You're welcome :grin:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.