forked from Ada-C8/Random-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_menu_generator.rb
More file actions
31 lines (26 loc) · 1.08 KB
/
random_menu_generator.rb
File metadata and controls
31 lines (26 loc) · 1.08 KB
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
def user_prompt(array, num_items)
puts "Please provide at least #{num_items} #{array} you would use to describe food. Separate each word with a space:"
# split string into individual words
array = gets.chomp.split(" ")
# check that there are enough words to fill the menu
until array.length >= num_items
puts "That was not enough adjectives. Please enter #{num_items} or more words:"
array = gets.chomp.split(" ")
end
# give each item proper capitalization
return array.each { |adj| adj.capitalize! }
end
# greet user
puts "Welcome to the menu generator! How many menu items would you like to see today?"
num_items = gets.chomp.to_i
adjectives = user_prompt("adjectives", num_items)
methods = user_prompt("methods", num_items)
foods = user_prompt("foods", num_items)
rand_adjs = adjectives.sample(num_items)
rand_methods = methods.sample(num_items)
rand_foods = foods.sample(num_items)
# match the randomized array elements by index and print menu items
puts "Menu du jour:"
num_items.times do |i|
puts "#{i + 1}. #{rand_adjs[i]} #{rand_methods[i]} #{rand_foods[i]}"
end