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 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,835 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!