Created
January 25, 2019 09:52
-
-
Save ChantalDemissie/e682018b75d88222b0622cae28daae74 to your computer and use it in GitHub Desktop.
This file contains 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
puts "How many close friends do you have?" | |
num_closefriends = gets.chomp.to_i | |
puts "Please enter the names, ages and favorite colors of your close friends" | |
friends = [] | |
num_closefriends.times do | |
friend = {} | |
puts "What is your friend's name?" | |
friend[:name] = gets.chomp | |
puts "What is their age?" | |
friend[:age] = gets.chomp.to_i | |
puts "What is their favorite color?" | |
friend[:color] = gets.chomp | |
friends.push(friend) | |
end | |
under18 = [] | |
friends.each do |friend| | |
if friend[:age] < 18 | |
under18.push(friend[:name]) | |
end | |
end | |
puts "you have #{under18.length} friends under 18: #{under18}" | |
colors = [] | |
friends.each do |friend| | |
colors.push(friend[:color]) | |
end | |
colors = colors.uniq | |
puts "your friends have #{colors.length} unique favorite colors, they are #{colors}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment