diff --git a/README.md b/README.md index 4befde5..2452fcf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Random Menu Generator +# 20180205 Ruby Practice; Random Menu Generator ## At a Glance diff --git a/nicoletta_random-menu.rb b/nicoletta_random-menu.rb new file mode 100644 index 0000000..4a9437e --- /dev/null +++ b/nicoletta_random-menu.rb @@ -0,0 +1,13 @@ +adjectives = ["sweet", "sour", "icky", "yummy", "salty", "crunchy", "gross", "pickled", "cold", "spicy"] +methods = ["fry", "roasted", "baked", "saute", "frozen", "smoked", "steamed", "toasted", "melted", "burned"] +foods = ["eggplant", "califlower", "squash", "tofu", "potato", "apples", "ice-cream", "chocolate", "beans", "mango"] + +10.times do |item| + # pick random element from array and remove it + adjective = adjectives.delete_at(rand(adjectives.length)) + method = methods.delete_at(rand(methods.length)) + food = foods.delete_at(rand(foods.length)) + + puts "#{item + 1}. #{adjective} #{method} #{food}" + +end diff --git a/random-menu.rb b/random-menu.rb new file mode 100644 index 0000000..b9fffa8 --- /dev/null +++ b/random-menu.rb @@ -0,0 +1,76 @@ +adjectives = [ + "hot", "cold", "soft", "chunky", "weird", "fresh", "strange", "blue", "spicy", + "old" +] + +cooking_styles = [ + "steamed", "fried", "toasted", "buried", "wood-fired", "pressure-cooked", + "sauted", "smoked", "chopped", "diced" +] + +foods = [ + "ice-cream","pizza", "pasta", "clams", "tofu", "sushi", "watermellon", + "veggie-burgers", "yogurt", "salmon" +] +# Original program - +# 10.times do |num| +# random = rand(foods.length) +# +# puts "#{num + 1}. #{adjectives[random]} #{cooking_styles[random]} #{foods[random]}" +# end + +# Optional Enhancement 1 +# 10.times do |num| +# random = rand(foods.length) +# +# # chooses random words +# adjective = adjectives[random] +# cooking_style = cooking_styles[random] +# food = foods[random] +# +# puts "#{num + 1}. #{adjective} #{cooking_style} #{food}" +# +# # removes terms/elements from each array as they are used +# adjectives.delete(adjective) +# cooking_styles.delete(cooking_style) +# foods.delete(food) +# end + +# Optional Enhancement 2 +class String + def numeric? + Float(self) != nil rescue false + end +end + +print "Please choose how many menu items you would like. You may choose 0 to 10 items: " +input = gets.chomp + +# TODO: Put this block of code into the while loop below to prevent accidental +# non-numaric input +until input.numeric? + print "#{input} is not a number. Please enter a number: " + input = gets.chomp +end +input = input.to_i + +while input > 10 + print "#{input} is more than the items availible. Please enter a number 0 to 10: " + input = gets.chomp.to_i +end + +input.times do |num| + random = rand(foods.length) + + # chooses random words + adjective = adjectives[random] + cooking_style = cooking_styles[random] + food = foods[random] + + puts "#{num + 1}. #{adjective} #{cooking_style} #{food}" + + # removes terms/elements from each array as they are used + adjectives.delete(adjective) + cooking_styles.delete(cooking_style) + foods.delete(food) +end