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 trialManne M
2,494 PointsWhere 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
Treehouse Moderator 145,860 PointsHi 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! :)
Mustafa Başaran
28,046 PointsHi 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)