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?
Your code appears to work correctly:
testing output:
personally, I hate using instance variables, in a "global variable" way, and would want to pass in the number that was being checked:
testing:
if you really wanted to set the instance
@fruitsvariable, you would be better off doing this: