Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions random-menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Prints a welcome message
puts "Welcome to my random menu generator! "

# Defines three arrays whose elements are foods or food descriptors
adjs = [
"creamed",
"warm",
"spicy",
"steamed",
"seasoned",
"barbecued",
"chilled",
"peppered",
"baked",
"steamed"
]

key_ingredients = [
"panceta",
"lentil",
"strawberry",
"shiitake",
"jalapeno",
"corn",
"tofu",
"chicken",
"bacon",
"lavender"
]

dishes = [
"soup",
"curry",
"salad",
"cake",
"creme brulee",
"meatloaf",
"chili",
"pizza",
"sushi",
"pancakes"
]

# Randomly rearranges the order of the elements in each array
adjs = adjs.shuffle

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of shuffle! This is a clever way to get a random order without destroying the array as you go along.

key_ingredients = key_ingredients.shuffle
dishes = dishes.shuffle

# Prompts the user to define the number of dishes, not allowing it to exceed 10
print "How many items would you like on your menu (max 10)? "
item_number = gets.chomp.to_i
if item_number > 10
item_number = 10
end

# Prints the randomly generated menu for the user
puts "\nHere is your menu:"
item_number.times do |item|
puts "#{item + 1}. #{adjs[item]} #{key_ingredients[item]} " +
"#{dishes[item]}"
# Generates a menu allowing items to be used more than once
# puts "#{item + 1}. #{adjs[rand(0...item_number)]} " +
# "#{key_ingredients[rand(0...item_number)]} " +
# "#{dishes[rand(0...item_number)]}"
end