Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Christopher Bush
Courses Plus Student 8,382 PointsWhat is wrong with my answer?
I dont understand why this is wrong.
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?
if(@todo_items.length == 0)
return true
else
return false
end
end
3 Answers

Maciej Czuchnowski
36,440 PointsYou're missing one end
after the return false
line.

Christopher Bush
Courses Plus Student 8,382 Pointsthanks I don't know why I didn't notice that.
William Li
Courses Plus Student 26,867 Pointsthough not related, I'd like point out that you can shorten your empty?
method like this:
def empty?
@todo_items.length==0
end
And it behaves exactly the same.

dotz
6,733 Points"The method should return false if there is more than one element in the @todo_items array."
I'm confused on this one. My code included a conditional to return false ONLY if there was MORE THAN ONE item in the array (meaning greater than 1)
def empty?
if @todo_items.empty?
return true
end
if @todo_items.length > 1
return false
end
end
but the code that passes is
def empty? @todo_items.empty? end
should the question say "at least one element"? I don't see this asked elsewhere - what am I misunderstanding? Thanks everyone!
William Li
Courses Plus Student 26,867 Pointsshould the question say "at least one element"? I don't see this asked elsewhere - what am I misunderstanding?
No, you are not misunderstanding, and I agree that "at least one element" is a much better description for what this challenge is asking for.