Iterating Over a Hash


Error message that I see: "Oops, try again. It looks like you aren't printing the value part of each key-value pair on its own line. Check the hint if you need help!"

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

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

What am I doing wrong?


Could be formatting. Technically you aren't putting the order on it's own line, you are putting a space, the order, and another space.

Also, you don't need to use interpolation in the block
Try puts order instead


Thanks for your help! I literally just changed "puts " #{order} " " to "puts order" and that seemed to work. It is weird though because the output that is showing is the exact same as what I showed above, but it still worked. (May be a glitch. I'm not sure.)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.