Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Collect user's three favorite foods
- # store them in an array, then print them out as a string
- # First we name the method and end it:
- def fav_foods
- food_arr = []
- # ask the user's favorite food with a times loop
- 3.times do
- puts "Name a favorite food."
- # lets collect those and use the shovel operator to put them
- # into our array.
- food_arr << gets.chomp
- end
- # p food_arr.each do |food|
- # puts "I like #{food} too!"
- # food_arr.each { |food| "I like #{food} too!"}
- #end
- #use the join method to print these to the terminal
- puts "Your favorite food are #{food_arr.join(", ")}."
- end
- fav_foods
Add Comment
Please, Sign In to add comment