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

Nick Evershed
Nick Evershed
5,536 Points

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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,936 Points

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 23,526 Points

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

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 23,526 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
Nick Evershed
Nick Evershed
5,536 Points

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