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 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
Jason Anders
Treehouse Moderator 145,546 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,021 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

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

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 "------" 

shop_list = create_list()

answer = ""

while answer != "q"
  item = add_list_item()
  print "Enter q to quit "
  answer = gets.chomp
  break if answer == "q"