Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Random Menu Generator
# 20180205 Ruby Practice; Random Menu Generator

## At a Glance

Expand Down
13 changes: 13 additions & 0 deletions nicoletta_random-menu.rb
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions random-menu.rb
Original file line number Diff line number Diff line change
@@ -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