Skip to content

Instantly share code, notes, and snippets.

@nthj
Last active December 30, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nthj/7875541 to your computer and use it in GitHub Desktop.
Save nthj/7875541 to your computer and use it in GitHub Desktop.
# Quiz Exercise, Part One
#
# Quiz for a list of names & birthdays,
# then list out their ages
#
# For example:
#
# Hey there! Please enter a list of names:
# > John, Sam, Bob, Alisha, Henry
#
# Thanks. When is John's birthday? 10/13/2000
#
# OK, and Sam's birthday? 8/3/1987
# And Bob's? 2/17/1957
# Alisha's? 4/21/1978
# Henry's? 6/23/1980
#
# OK, all done. You have 5 guests. Here are their ages:
#
# * John: 13
# * Sam: 26
# * Bob: 56
# * Alisha: 35
# * Henry: 33
#
# Enjoy your party!
#
##
## OUTLINE
##
# We're going to want to break the problem down into steps.
# First, let's ask for the user's input:
puts "Hey there! Please enter a list of names:"
guest_names = 'John, Sam, Bob, Alisha, Henry' # TODO: ask for input
# We want to loop (or iterate) over each name.
# * What type of data do we have in the `guests` variable?
# * What type of data supports iteration?
# * How do we transform the first into the second?
list_of_guest_names = []
guests = []
list_of_guest_names.each do |guest_name|
guest_birthday = '10/27/1978' # TODO: ask them their birthday
person = {
:name => guest_name,
:age => 15 # TODO: calculate this based on their birthday
}
# Store this value into the `guests` array
guests << person
end
# We want to display the data onto the screen.
#
# * How many guests do we have total?
# * What are their names and ages?
puts "All done. You have ? guests. Here are their ages:"
# TODO: loop over each guest
##
## EXTENSION #1
##
# Ask for a few more pieces of information:
#
# * Are they bringing a gift? (true or false)
# * Display how many people are bringing a gift.
##
## EXTENSION #2
##
# * How many friends are they bringing? (0, 1)
# * Update the "number of guests" to take the friends' numbers into account:
#
# "You have 5 guests who are bringing 2 friends for a total of 7 people."
##
## EXTENSION #3
##
# Calculate how much the party will cost.
# * Estimate $5 for each person, including the friends that guests are bringing.
# * Add an extra $3 for each person over 21, as they will drink our alcohol
# * Provide a $2 discount for each senior citizen
##
## EXTENSION #4
##
# Display a receipt for the total party cost
# * Display each person as a line-item ($5)
# * Display each alcohol addition
# * Display each discount
# * `rjust` or `ljust` (string methods) each column and value so everything lines up nicely
# EXAMPLE:
# * Nathaniel: $5
# * John: $5
# * Sam: $5
# * John Alcohol: $3
# * Sam Alcohol: $3
# * John Senior: ($2)
# * Subtotal: $19
# * Tax: $1.90
# * Total: $21.90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment