Guest User

Untitled

a guest
Jul 17th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Collect user's three favorite foods
  2. # store them in an array, then print them out as a string
  3. # First we name the method and end it:
  4. def fav_foods
  5. food_arr = []
  6. # ask the user's favorite food with a times loop
  7. 3.times do
  8. puts "Name a favorite food."
  9. # lets collect those and use the shovel operator to put them
  10. # into our array.
  11. food_arr << gets.chomp
  12. end
  13. # p food_arr.each do |food|
  14. # puts "I like #{food} too!"
  15. # food_arr.each { |food| "I like #{food} too!"}
  16. #end
  17. #use the join method to print these to the terminal
  18. puts "Your favorite food are #{food_arr.join(", ")}."
  19. end
  20.  
  21. fav_foods
Add Comment
Please, Sign In to add comment