Welcome to the Treehouse Community
Looking to learn something new?
Unable to complete the empty? method Challenge
Alright, this one has me totally lost. I watched the video three times and checked my work and still can't figure it out? Can anyone help?? Thanks! I have attached my code.
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) index = 0 found = false todo_items.each do |todo_item| if todo_item.name == name found = true end if found break else index += 1 end end if found return index else return false end end end
In the TodoList class, fill in the empty? method to return a boolean value. The empty? method should return true if there are no elements in the @todo_items array. The method should return false if there is more than one element in the @todo_items array.
Here's alternative way, Ruby doesn't require to use implicit return, we can look
@todo_items =  under initialize, that's empty array, right?
Best way is to use empty? method, that's what the question asked.
def empty? todo_items.empty? # this method will return true if array is empty end
It will return true due to . Hope that helps.
Ouch, I wasn't even close. The early stuff was easy to learn but this Boolean stuff is almost over my head. My brain is starting to hurt (hahahaha).
Thanks, Salman. I couldn't figure out the next one either and posted a new question to the forum; perhaps you could advise on that one too if you're still online...