From 6806cd96b888b570444117f880a22c48bd288df9 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Mon, 5 Feb 2018 15:14:21 -0800 Subject: [PATCH 1/4] adds date and short descript to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From df6ce477e577d027dc2b9ec5289fcf9b68361d26 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Mon, 5 Feb 2018 17:21:48 -0800 Subject: [PATCH 2/4] develops random-menu program --- random-menu.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 random-menu.rb diff --git a/random-menu.rb b/random-menu.rb new file mode 100644 index 0000000..d612e6e --- /dev/null +++ b/random-menu.rb @@ -0,0 +1,36 @@ +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 + +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 From 8e7cb343ecaa1956da78117db41875de4227219d Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Mon, 5 Feb 2018 21:28:38 -0800 Subject: [PATCH 3/4] adds optional enhancement2: user select number of menu items --- random-menu.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/random-menu.rb b/random-menu.rb index d612e6e..b9fffa8 100644 --- a/random-menu.rb +++ b/random-menu.rb @@ -19,7 +19,47 @@ # puts "#{num + 1}. #{adjectives[random]} #{cooking_styles[random]} #{foods[random]}" # end -10.times do |num| +# 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 From 3454ed7ec14a9586974a721851934f3577593759 Mon Sep 17 00:00:00 2001 From: Kate Pond Date: Mon, 5 Feb 2018 21:45:23 -0800 Subject: [PATCH 4/4] adds nicoletta's cool code for refrence re: method .delete_at --- nicoletta_random-menu.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 nicoletta_random-menu.rb 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