Skip to content

Instantly share code, notes, and snippets.

@kdefliese
Created September 24, 2015 22:05
Show Gist options
  • Save kdefliese/b1c03482b9ecbcd2524b to your computer and use it in GitHub Desktop.
Save kdefliese/b1c03482b9ecbcd2524b to your computer and use it in GitHub Desktop.
Random menu generator
puts "Hello! This is a random menu generator"
# I added the user-submitted words to my original arrays because it was kind of annoying for the user to have to input 30+ words on the command line...
user_adjectives = ["hot","cold","tasty","spicy","bland","overcooked","raw","disgusting","burned","crispy"]
user_cooking_styles = ["pan-seared","baked","broiled","deep-fried","roasted","julienned","boiled","microwaved","stir-fried","barbecued"]
user_foods = ["yams","bread","peanut butter and jelly sandwiches","yogurts","chia seeds","chocolates","tacos","burritos","gravy","applesauce"]
puts "Let's add some items to the menu!"
3.times { puts "Enter an adjective:"
new_adj = gets.chomp
user_adjectives.push(new_adj) }
3.times { puts "Now enter a cooking style:"
new_cooking_style = gets.chomp
user_cooking_styles.push(new_cooking_style) }
3.times { puts "Okay, enter a food:"
new_food = gets.chomp
user_foods.push(new_food) }
puts "How many menu items would you like to see?"
menu_items = gets.chomp.to_i
if menu_items > user_adjectives.length
puts "We don't have that many menu items! Please try again and ask for fewer items."
else
total = 1
while total <= menu_items
adjective = user_adjectives[rand(user_adjectives.length)]
cooking_style = user_cooking_styles[rand(user_cooking_styles.length)]
food = user_foods[rand(user_foods.length)]
puts "#{total}. #{adjective} #{cooking_style} #{food}"
total += 1
user_adjectives.delete(adjective)
user_cooking_styles.delete(cooking_style)
user_foods.delete(food)
end
end
# original solution for primary requirements
# adjectives = ["hot","cold","tasty","spicy","bland","overcooked","raw","disgusting","burned","crispy"]
# cooking_styles = ["pan-seared","baked","broiled","deep-fried","roasted","julienned","boiled","microwaved","stir-fried","barbecued"]
# foods = ["yams","bread","peanut butter and jelly sandwiches","yogurts","chia seeds","chocolates","tacos","burritos","gravy","applesauce"]
# total = 1
# adjectives.each do |n|
# puts "#{total}. #{adjectives[rand(9)]} #{cooking_styles[rand(9)]} #{foods[rand(9)]}"
# total += 1
# end
@kariabancroft
Copy link

What will happen if the user enters duplicate values into the food arrays?

@kariabancroft
Copy link

I like the way you've built your while loop to do the final output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment