From a5e45e3ca259ebb986eabf6f72a2f6d491a529ea Mon Sep 17 00:00:00 2001 From: npeters5 Date: Tue, 6 Feb 2018 11:11:55 -0800 Subject: [PATCH 1/2] My Random Menu --- random_menu.rb | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 random_menu.rb diff --git a/random_menu.rb b/random_menu.rb new file mode 100644 index 0000000..8059362 --- /dev/null +++ b/random_menu.rb @@ -0,0 +1,87 @@ +# Come up with the three arrays of ten items each. Each list should be a different type of food or descriptor for that food. For example, the first array can contain adjectives, the second, cooking styles and the third, foods. + +adjectives = ["spicy", "salty", "sweet", "savory", "saucy", "bitter", "sour", "buttered", "Korean", "Italian"] +styles = ["fried", "baked", "sauteed", "broiled", "steamed", "roasted", "sous-vide", "wood-fired", "grilled", "smoked"] +foods = ["potatoes", "halibut", "tofu", "sirloin", "veggies", "eggs", "zoodles", "stir-fry", "curry", "pasta"] + +# Your generator should pull one item from each array you made in the baseline requirements to create a "menu item". +# When the program runs, it should create and show a list of ten numbered menu items. + +# 10.times do |i| +# puts "#{i + 1}. #{adjectives.sample} #{styles.sample} #{foods.sample}" +# end + +# Optional Enhancements +# Expand your solution to ensure that no descriptive term in a menu item is ever repeated. So if the first menu item is hot pan-fried dumplings, then the phrases hot, pan-friend and dumpling cannot individually be used in any other menu items. + +10.times do |i| + adjective = adjectives[rand(adjectives.length)] + style = styles[rand(styles.length)] + food = foods[rand(foods.length)] + puts "#{i + 1}. #{adjective} #{style} #{food}" + adjectives.delete(adjective) + styles.delete(style) + foods.delete(food) +end + +# Expand your solution to allow the user to determine how many items they'd like to see via user input. Note: You will need to ensure that this user-chosen number of items is not larger than the number of items you have in your arrays. + +puts "How many menu items would you like to see?" +num = gets.chomp.to_i + +until (num >= 1) && (num <= 10) + puts "Please enter a number between 1 and 10." + num = gets.chomp.to_i +end + +num.times do |i| + puts "#{i + 1}. #{adjectives.sample} #{styles.sample} #{foods.sample}" +end + +# Instead of using hardcoded or predefined arrays, make your program accept user input. This user input will be utilized to generate the menu items. You'll need to prompt for and store a varying number of entries for each food-type array. + +adjectives = [] +styles = [] +foods = [] + +puts "Welcome to the random menu generator! We're going to start by entering some adjectives about food." + +5.times do + print "Please enter an adjective (ex: salty): " + adjective = gets.chomp.downcase.to_s + adjectives << adjective +end + +puts "Now we're going to enter some cooking styles." + +5.times do + print "Please enter a cooking style (ex: broiled): " + style = gets.chomp.downcase.to_s + styles << style +end + +puts "Now we're going to enter some foods." + +5.times do + print "Please enter an adjective (ex: potatoes): " + food = gets.chomp.downcase.to_s + foods << food +end + +puts "Now, how many random menu items would you like to see?" +num = gets.chomp.to_i + +until (num >= 1) && (num <= 5) + puts "Please enter a number between 1 and 5." + num = gets.chomp.to_i +end + +num.times do |i| + adjective = adjectives[rand(adjectives.length)] + style = styles[rand(styles.length)] + food = foods[rand(foods.length)] + puts "#{i + 1}. #{adjective} #{style} #{food}" + adjectives.delete(adjective) + styles.delete(style) + foods.delete(food) +end From 2c9a24a9b2cc6b55d345b28cea615296a5dd722c Mon Sep 17 00:00:00 2001 From: Nora Peters Date: Tue, 6 Feb 2018 11:47:58 -0800 Subject: [PATCH 2/2] Update random_menu.rb --- random_menu.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/random_menu.rb b/random_menu.rb index 8059362..d447bc9 100644 --- a/random_menu.rb +++ b/random_menu.rb @@ -63,7 +63,7 @@ puts "Now we're going to enter some foods." 5.times do - print "Please enter an adjective (ex: potatoes): " + print "Please enter an food (ex: potatoes): " food = gets.chomp.downcase.to_s foods << food end