forked from Ada-C8/Random-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_menu.rb
97 lines (69 loc) · 1.82 KB
/
random_menu.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#Array list
adjectives = []
styles = []
foods = []
puts
puts "Welcome to the Random Menu Generator"
puts
puts "How many food items do you want to create? Please enter a number."
puts
#rescue for number?
food_number = gets.chomp.to_i
#Redundant loops checking if the number of adjectives, cooking styles,
#and foods match the number of menu items requested.
until adjectives.length == food_number do
puts
puts
puts "Please give me a list of your one word food adjectives equal to the number of"
puts "menu items you want to create separated by a space:"
puts
user_adjectives = gets.chomp.to_s
adjectives = user_adjectives.split(/ /)
if adjectives.length != food_number
adjectives.clear
else
puts
puts "Thank you!"
end
end
until styles.length == food_number do
puts
puts
puts "Please give me a list of one word cooking styles equal to the"
puts "number of menu items separated by a space:"
user_styles = gets.chomp
styles = user_styles.split(/ /)
if styles.length != food_number
styles.clear
else
puts
puts "Thank you!"
end
end
until foods.length == food_number do
puts
puts
puts "Please give me a list of one word foods equal to the number"
puts "of menu items separated by a space:"
user_foods = gets.chomp
foods = user_foods.split(/ /)
if foods.length != food_number
foods.clear
else
puts
puts "Thank you!"
end
end
puts
puts
puts "Here is your menu:"
puts
#Creates menu by grabbing a random element from each array as an object,
#deleting it from the array, and adding it to instance variable menu_item.
i = 0
food_number.times do
i = i +1
menu_item = adjectives.delete(adjectives.sample) + " " + styles.delete(styles.sample) + " " + foods.delete(foods.sample)
puts "#{i}" + "." + " " + "#{menu_item}"
end
puts