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.

Ruby

Mikey Neilson
seal-mask
.a{fill-rule:evenodd;}techdegree
Mikey Neilson
Front End Web Development Techdegree Student 12,642 Points

removing item from shopping list with ruby

hey i'm after a little help with making a basic shopping list with ruby, I want user to be able to add items and remove if they wish.I have got the add items part working but i'm struggling with the remove items . Any help with this would be amazing here is my code so far.......

    def create_list
    print "whats the name of the list: "
    name = gets.chomp.capitalize

    hash = {"name" => name, "items" => Array.new}
    return hash
end

def add_to_list

    print "What items do you want to add: "
    item_name = gets.chomp.capitalize
    print "How much: "
    quantity = gets.chomp.to_i

    hash = {"name" => item_name, "quantity" => quantity}
    return hash
end

def print_list(list)
    puts "-" * 30
    puts "Name: #{list['name']}"
    puts "-" * 30

    list['items'].each do|item|
        puts "Name: #{item['name']}"
        puts "Quantity: #{item['quantity']}"

    end
    puts "-" * 30
end
def remove_item(list)
    print "Do you want to remove item from shopping list? Enter y/n: "
    answer = gets.chomp
    if answer == "n"
        print "Ok your #{list['item_name']} is finished"

    elsif answer == "y"
        print "Enter the item you would like to remove: "
        remove = gets.chomp.capitalize
        list['items'].each do|i|
            end
            return i
        end
        #list['items'].delete(remove)
    else 
        print "answer y/n only. "

end
return remove
end


list = create_list()

list['items'].push(add_to_list())
list['items'].push(add_to_list())



print_list(list)
remove = remove_item(list)
remove['list'].delete(remove_item(remove))
print_list(list)