When iterating over hashes, we need two placeholder variables to represent each key/value pair.

restaurant_menu = { "noodles" => 4, "soup" => 3, "salad" => 2 } restaurant_menu.each do |item, price| puts "#{item}: #{price}" end
  1. In the example above, we create a new hash called restaurant_menu.
  2. Then, we loop through the restaurant_menu hash and assign the key to item and the value to price for each iteration.
  3. Finally, we puts out:
noodles: 4 soup: 3 salad: 2



Use .each to iterate over the secret_identities hash.

Use puts to print each key-value pair, separated by a colon and a space (:), to the console, just like the example above.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?