Ruby Ruby Collections Build a Grocery List Program Build a Grocery List Program: Part 4

Where can I find the extra credit assignment?

I can't seem to find the extra credit assignment that is mentioned in the video and discussed on the forums.

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,840 Points

Hi Manne,

Extra Credit suggestions aren't actual assignments, but rather suggestions on what to practice. Here, if you go to the Home page for the course and expand the "Build a Grocery List Program" section, there will be a little snippet that give you the Extra Credit suggestion:

On your own, research how to use loops and modify our grocery list program to continually ask for input rather than only ask for three different items.

Keep Coding! :) :dizzy:

Mustafa Başaran
Mustafa Başaran
28,018 Points

Hi Manne,

Here is my take on it using a while loop. best regards, Mustafa

def create_list
  print "What is the name of the list? "
  name = gets.chomp
  hash = { "name" => name, "list" => Array.new }
  return hash
end

def add_list_item 
  print "What is the item? "
  item_name = gets.chomp  
  print "What is the quantity? "
  quantity = gets.chomp.to_i
  hash = { "name" => item_name, "quantity" => quantity }
  return hash
end


def print_list(list)
  puts "SHopping List Name: #{list["name"]}"
  puts "------"  
  list["list"].each do |item|
    puts "Item Name: #{item["name"]}"
    puts "Item Quantity: #{item["quantity"].to_s}"
    puts "------" 
  end
end



shop_list = create_list()

answer = ""

while answer != "q"
  item = add_list_item()
  shop_list["list"].push(item)
  print "Enter q to quit "
  answer = gets.chomp
  break if answer == "q"  
end


print_list(shop_list)