Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSoumya Veer
3,484 PointsAdding empty method and returning true and false.
I am getting the result when I am doing it separately but not sure if this is what is expected, because I keep getting message "Bummer! Try again" . I must be going wrong somewhere for sure but cant figure out.
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?
count = 0
count = todo_item.length
if count == 0
puts "true"
return true
elsif count > 1
puts"false"
return false
end
end
end
2 Answers
Jennifer Nordell
Treehouse TeacherI'm of the opinion that outside the challenge, your code would probably work. However, challenges are picky about what information you put in them. Try not to do things it doesn't specifically ask for. In your case you've included a couple of "puts" statements and introduced a variable "count" which it probably isn't expecting. Take a look at my code to see how I passed the challenge.
def empty?
if todo_items.length == 0
return true
elsif todo_items.length > 1
return false
end
end
Soumya Veer
3,484 PointsGot it.. Looks like you are right. I removed the extra variables and passed it...Thank you so much for the help.