Skip to content

Instantly share code, notes, and snippets.

@trowbrsa
Created September 25, 2015 04:27
Show Gist options
  • Save trowbrsa/d5348a1309c53da32b98 to your computer and use it in GitHub Desktop.
Save trowbrsa/d5348a1309c53da32b98 to your computer and use it in GitHub Desktop.
Sarah Trowbridge's Random Menu Generator. Note that the met the primary requirements were met for this project and I attempted some of the optional enhancements but the enhancements are incomplete. I am going to return to this at a later time to complete it.
puts "Welcome to the internet's most random food generator!"
puts "How many dishes can we tantilize you into reviewing today? Select a number between 1 and 10."
number_of_dishes = gets.chomp
if number_of_dishes.to_i > 10
puts "That's a bigger number than the number of dishes our chef can cook! Please select a lower number."
#Need to figure out a way to have the program not continue if they select a larger number than 10.
elsif number_of_dishes.to_i >= 1 && number_of_dishes.to_i <=10
puts "#{number_of_dishes.to_i} dishes, excellent choice!"
else
puts "That's not a number, silly. Let's go with 8 dishes!"
dishes = number_of_dishes.to_i
dishes = 8
end
#Note - I haven't figured out a way to incorporate the users input and generate the below based on their response.
#I also haven't figured out to how to ensure that the user does not see repeating options.
adjective = ["steamy", "stinky", "smooth", "slimy", "sweet", "succulent", "aromatic", "flaky", "slippery", "bountiful"]
cooking_style = ["chilled", "crisp-fried", "burnt", "plucked", "skinned", "mushed", "sizzled", "smoked", "flash-fried", "frozen"]
food = ["squid legs", "octopus eye", "salmon scales", "shark fin", "sea snail", "baby star fish", "seaweed", "tuna sandwhich", "clam bake", "turtle head"]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
adjective.shuffle.delete(adjective)
cooking_style.shuffle.delete(cooking_style)
food.shuffle.delete(food)
puts "Today's delicacy will be..."
numbers.each do |n|
puts "#{n}. #{adjective[rand(10)]} #{cooking_style[rand(10)]} #{food[rand(10)]}"
end
@kariabancroft
Copy link

Per your comment on line 6, you could utilize a while loop which could allow you to repeatedly ask for user input until the user entered a valid number

@kariabancroft
Copy link

In your else on line 9, it seems like line 11 is not necessary since your program will ignore the user-input value and reset it to 8

@kariabancroft
Copy link

Take a look at the docs for the shuffle method. I don't think it is shuffling it the way you think it is. I think the one you would ultimately want is the shuffle!. We haven't really talked about the differences, but the docs should explain it a bit: http://ruby-doc.org/core-2.2.0/Array.html#method-i-shuffle

@kariabancroft
Copy link

Nice job with your final each loop. Hopefully now you see how you might be able to use a range rather than create this separate numbers array which would do the same type of thing for you.

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