Iterating Over a Hash


#1


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


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} "
end



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

What am I doing wrong?


#2

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


#3

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.)


#4

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