jeudi 4 février 2021

Why will my if and els-if statement within my ruby method not work

I am trying to create a ruby class with a method that takes ages into account. While the if elsif method works for producing 100 fruits for trees over the age of 5 and less than 10. Any tree over the age of 10 and less than 15 should produce 200 but don't?

def grow_fruits
    if @age <= 5
      @fruits = 0
    elsif @age < 10
      @fruits = 100
    elsif @age < 15
      @fruits = 200
    else
      @fruits = 0
    end
  end

I have tired @age <= 10 && @ < 15 but agai no response?

Aucun commentaire:

Enregistrer un commentaire