I'm really lost here ..... data structures (16)


#1



https://www.codecademy.com/courses/ruby-beginner-en-F3loB/3/3?curriculum_id=5059f8619189a5000201fbcb#


Struggling to make this work .... any ideas ? Maybe just a hint. I don't want solution on a silver platter.


lunch_order = {
  "Ryan" => "wonton soup",
  "Eric" => "hamburger",
  "Jimmy" => "sandwich",
  "Sasha" => "salad",
  "Cole" => "taco"
}
lunch_order = ["Ryan", "Eric", "Jimmy", "Sasha", "Cole"]
puts lunch_order.each {lunch_order}
end

UPDATED CODE (still not working though)

lunch_order = {
  "Ryan" => "wonton soup",
  "Eric" => "hamburger",
  "Jimmy" => "sandwich",
  "Sasha" => "salad",
  "Cole" => "taco"
}
lunch_order = ["wonton soup", "hamburger", "sandwich", "salad", "taco"]
puts lunch_order.each {lunch_order}
end


#2
object . method { block }

The each method iterates over the object, and executes the block on each iteration.

{ | block parameters |  block action }

So,

lunch_order.each { | name, order | puts "#{name}: #{order}" }

but if we just want to print the orders,

lunch_order.each { | name, order | puts "#{order}" }

#3

Thank you for your help.

This is what I've got so far:

lunch_order = {
"Ryan" => "wonton soup",
"Eric" => "hamburger",
"Jimmy" => "sandwich",
"Sasha" => "salad",
"Cole" => "taco"
}
lunch_order = ["wonton soup", "hamburger", "sandwich", "salad", "taco"]
lunch_order.each {|name, order| puts "#{order}" }

Orders are being printed out but goes on one line and not each one on separate line.


#4

This should be given a different variable name (or removed) so it does not conflict with the hash.

For an array, we would write,

lunch_orders = ["wonton soup", "hamburger", "sandwich", "salad", "taco"]

lunch_orders.each { |order| puts "#{order}" }

#5

The error I'm getting says I need print out just the values.
But can't figure out how to make it happened. This exercise is really cracking my neck .....

Thank you for your input mate ...

This is the updated code I've got ... obviously it's not complete .... don't know what to do and why.

lunch_order = {
"Ryan" => "wonton soup",
"Eric" => "hamburger",
"Jimmy" => "sandwich",
"Sasha" => "salad",
"Cole" => "taco"
}

lunch_order.each {|order_order| print "#{}" }


#6

    lunch_order.each {|name, order| puts "#{order}" }

#7

Gee ! It's really this simple .... :open_mouth:
Thank you dude ! I can finally carry on ....


#8

Simple is never as easy as it looks. Good that you had a bit of a struggle, in my books.


#9

Yeah this one gave me quite a bit of headache .... once again thanks very much for your time. Appreciate it ! Have a great day mate !