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 trial

Ruby

Andrew Gargano
seal-mask
.a{fill-rule:evenodd;}techdegree
Andrew Gargano
Front End Web Development Techdegree Student 6,603 Points

ToDo List

Hello,

Can anyone please tell why I'm getting the below error on the below code?

"odo_list.rb:62:in <class:TodoList>': undefined methodmark_complete' for #<TodoList:0x005614cf 1eb970> (NoMethodError) from todo_list.rb:3:in `<main>'

Code:

    require "./todo_item"

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 remove_item(name) if index = find_index(name) todo_items.delete_at(index) return true else return false end

def mark_complete(name) if index = find_index(name) todo_items[index].mark_complete! return true else return false end end end

def find_index(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 nil end end

todo_list = TodoList.new("Groceries") todo_list.add_item("Milk") todo_list.add_item("Eggs") todo_list.add_item("Bread")

if todo_list.remove_item("Eggs") puts "Eggs were removed from the list." end

if todo_list.mark_complete("Milk") puts "Milk was marked as complete." end puts todo_list.inspect end

Please format the Markdown so it's readable.

1 Answer

One error I found: use double equal signs

==

for equalities, not

=

or else Ruby thinks you are making a variable.