Stuck defining methods


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-ET4bU/1/4?curriculum_id=5059f8619189a5000201fbcb#


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


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

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

by_three (6)


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

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

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

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,

else
        return false
    end
end

#3

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


#4

You're welcome :grin:


#5

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