Help on 16 iterating over a hash


#1

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


#2

Here is the code that worked for me.

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

lunch_order.each do |person, meal|
puts "#{meal}"
end


#3

Hey daemon_x

did the exact code:
lunch_order.each do |people,food|
puts "{food}"
end

error: did not print key-value par. Shows up {#food}{#food}{#food}{#food}.? Any suggestions?


#4

instead of: puts "{food}"
try: puts "#{food}"

so it would look like this:
lunch_order.each do |people,food|
puts "#{food}"
end


#5

actually did put that in the code. Just forgot to type it there. but yeah same result:(


#6

Please copy-paste your whole code (don't retype it).


#7

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

lunch_order.each do |people,food|
puts "{#food}"
end


#8

It's #{food}, not {#food}.


#9

wow stupid mistake. Thanks!


#10

Thanks for posting this. I was stuck here for a minute


#11

I do have a question. I think I did the code in a right syntax with

lunch_order.each { |order| puts order}

it came out as the answer but don't understand other way is the correct one.