Last active
August 29, 2015 14:02
-
-
Save bomatson/7f1f970c28acc40a8212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Welcome to Restaurant 720" | |
puts | |
courses = {"appetizers" => ["nachos", "bloomin onion", "guacamole", "breadsticks", "garlic knots", "none"], | |
"entrees" => ["hamburger", "chicken strips", "fried chicken", "none"], | |
"desserts" => ["chocolate cake", "apple pie", "none"], | |
"drinks" => ["soda", "wine", "coffee", "tea", "none"]} | |
order = [] | |
# this is an awesome setup above! | |
def ordering(courses, order) | |
# I passed in two parameters to the ordering function. Since I define "order" and "courses" | |
# outside of the function, I need to pass them in in order to have access to them | |
puts "What course would you like?" | |
puts courses.keys | |
user_input = gets().chomp().downcase.to_s | |
puts | |
#everything above looks really great | |
courses[user_input].each_with_index do |item, index| | |
puts "#{index} : #{item}" | |
end | |
user_item = gets.chomp.to_i | |
order << user_item | |
# look carefully at what you are adding to the order array | |
end | |
5.times do |ordering| | |
# I added a loop here to allow your user to order up to 5 times | |
puts "Would you like anything ? (y/n)" | |
yn = gets.chomp | |
# you need to compare the user's answer to an actual string. In this case, it is "y" | |
if yn == 'y' | |
# I only call the ordering function if they want to order | |
ordering(courses, order) | |
else | |
# otherwise, I break out of the loop and end the session | |
break | |
end | |
end | |
puts "your order is: " | |
order.each do |item| | |
puts "#{item}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment