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

shopping.rb:38: syntax error, unexpected end-of-input, expecting keyword_end print_list(list)

def create_list
  print "What is the name of list? "
  name = gets.chomp

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

def add_list_item
  print "What is the item called? "
  item_name = gets.chomp

  print "How much? "
  qty = gets.chomp.to_i

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

def print_list(list)

    puts "List #{list['name']}"
    puts "------"

    list["items"].each do |item|
    puts "Item: " + item['name']
    puts "Quantity " + item['qty'].to_s
    puts "-------"

  end

list = create_list()
puts list.inspect
list["item"].push(add_list_item())

puts list.inspect

print_list(list)

1 Answer

The reason you are getting an error is because you never "end" your print_list block. The "end" that looks like it closes it is actually closing the each block 4 lines above it. The error itself was pretty good about telling you what was wrong.