Created
October 7, 2017 17:13
-
-
Save khan-hasan/9bac6e39a7d690a2f4812c0b5fa4b450 to your computer and use it in GitHub Desktop.
CF 3.3 | simple ruby program using loops, hashes, and arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fav_foods | |
| food_array = [] | |
| 3.times do | |
| puts "Name a favorite food." | |
| food_array << gets.chomp | |
| end | |
| 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're doing | |
| end # ends the loop | |
| p food_array | |
| puts "Your favorite foods are #{food_array.join(", ")}." | |
| end | |
| fav_foods | |
| my_hash = {"name": "Annie", "coins": 5, "password": "take my money", "favorite_foods": ["apples", "salami", "Ritter Sport candy bars"]} | |
| puts my_hash[:favorite_foods][0] # returns "apples" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment