Skip to content

Instantly share code, notes, and snippets.

@bmikol
Created February 19, 2017 05:26
Show Gist options
  • Select an option

  • Save bmikol/73323d36d1963ee61bf68fc704c836f6 to your computer and use it in GitHub Desktop.

Select an option

Save bmikol/73323d36d1963ee61bf68fc704c836f6 to your computer and use it in GitHub Desktop.
CareerFoundry Ex 3.3
def fav_foods
food_array = [] # Instead of the brackets, you can also use Array.new to make a new empty array
3.times do
puts "Name a favorite food."
food_array << gets.chomp
end
p food_array
puts "Your favorite foods are #{food_array.join(", ")}."
food_array.each do |food| # Do something to each element in food_array; that element is to be referred to as food
puts "I like #{food} too!" # The thing we are doing
end
# Also can be written as food_array.each { |food| puts "I like #{food} too!" }
end
fav_foods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment