# Event Countdown Code

Very often, a club or organization will have a big event (a
tournament, a show, a lecture, you name it) that it will want to
feature prominently on its website. In fact, as the event gets closer,
the club might want to feature it more prominently. Of course, once
the event is past, it should fade into the background.

You can use JavaScript to make these customizations, based on how far
away the event is. You can look at
the date dependent
code example to see how to do the customizations. This page describes
and demonstrates the JavaScript calculations necessary to find out how
far away the event is, based on the date of the event and the current
date.

## Customization Example

For this demonstration, we will assume that you are interested in how
many days remain until the polls open at 7am on the day of the 2016
election, namely November 8th, 2016.

What will we do with this information? The page will tell you how
many days remain, and it will adjust the font size based on how far away
the election is. (This will stand in for whatever adjustments you might
make for your own event.)

- if it's comfortably far away: 20px
- Less than 500 days: 24px
- Less than 365 days: 30px
- Less than 200 days: 36px
- Less than 100 days: 42px
- Less than 50 days: 52px
- Less than 10 days: 65px
- Tomorrow: 100px
- in the past: 10px.

## Customizations in Action

Just so you know, election day is

insert days here

## How It's done

There are several ways this could be done. Here's how we did the
computation:

- We created a Date object for our event.
We found the current Date as well.
- We use the
`.getTime()`

method on Date objects to
determine the number of milliseconds since the beginning of
time

(January 1st, 1970). The difference between these values
is the number of milliseconds from now until the election.
- We can divide that difference by the number of milliseconds in a day
to determine how many days there are between now and then.
- Chances are, that division won't be a whole number. The quotient
will be some kind of decimal, like 1.7. That value would mean the
election is one whole day and a bunch of hours from now. Since
election day is on a Tuesday, 1.7 would be the calculation on the
preceding Sunday. If you care about greater accuracy, you may have
to do a few more calculations to determine the exact number of hours
remaining. In the interests of simplicity, we didn't do that here.
- Based on the number of days remaining, make whatever content and
style adjustments you want to make.

Use view source

on this page to see exactly how we did
it.