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

A M
A M
1,397 Points

No implicit conversion of string into integer

Hi,

I'm experiencing some problems with my code, can someone please take a look and let me know what's wrong?

The mistake I get 'No implicit conversion of string into integer' seems to refer to the square brackets ["items"] on the last line of the code.

I'm a beginner so I'm not really sure what could cause this problem. I checked the class of the def create_list and it tells me it is a Fixnum (is this normal?) and I'm thinking maybe this is where the issue comes from?

Thanks!

def create_list
  print "What's the name of your grocery list? "
  list_input = gets.chomp

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

def add_grocery_item()
  print "What's on your grocery list? "
  item_name = gets.chomp

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

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

list = create_list()
list["items"].push(add_grocery_item())

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 46,127 Points

In create_list change the return value from hash to grocery_list_name, as that is the hash you are setting.

A M
A M
1,397 Points

Thanks so much, this makes sense!