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

Different output

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

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

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

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

list = create_list() puts list.inspect

add_list_item().inspect

I have copied what he did in the video exactly, but for some reason whenever I type the item the program ends and dosen't display name ==> "(What I typed)"

3 Answers

If you check the video @ 18 seconds he enters

puts add_list_item().inspect

you just have

add_list_item().inspect
Jeff Muday
Jeff Muday
Treehouse Moderator 26,896 Points

Kris, you beat me to another answer! You are the fastest gun in the west!

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 26,896 Points

That's a very simple fix, drop in a "puts" in front of the last add_list_item().inspect and you will have it.

Ruby is a super cool language, enjoy!

def create_list
  print "What is the list name? "
  name = gets.chomp
  hash = { "name" => name, "items" => Array.new }
  return hash
end

def add_list_item
  print "What is the item called? "
  item_name = gets.chomp
  hash = { "name" => item_name }
  return hash
end

list = create_list()
puts list.inspect

puts add_list_item().inspect # you needed a puts here

Yea Ruby seems like the perfect language for me, anyways thanks guys :)