Welcome to the Treehouse Community
Looking to learn something new?
Empty? method (returning Boolean values)
Okay, so I've gotten things up to this point as the syntax is fairly straightforward, but for some reason I keep getting a "bummer, try again" on this exercise. Am I missing something obvious?
Also wouldn't I get nil if there is only one item in the todo_items array?
class TodoList attr_reader :name, :todo_items def initialize(name) @name = name @todo_items =  end def add_item(name) todo_items.push(TodoItem.new(name)) end def empty?(name) if @todo_items == 0 return true else @todo_items >= 1 return false end end end
I just used a straight comparison with zero. However, I don't think this fits the challenge but the code does pass.
def empty? @todo_items.count == 0 end
The question isn't covering the scenario where there is one item in the array, as you say! However, the code is expecting only two outcomes; true or false, based on empty & not empty. The challenge code doesn't distinguish three states, empty; has one; has more than one.
I hope that helps,
Oh, okay! Sometimes the questions are not always so straightforward in interpretation (because naturally I'd think you'd have to cover three cases - empty, more than one, one - based on the wording of the question) but the clarification helps in terms of the exercise. Thanks!