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 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 28,716 Points

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

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 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 :)