The Code
The code is structured in ten functions. Called functions will be detailed in their own sections.
Click a headline() to scroll to that section of the code. And click
the
function name within the code to scroll to that write up section.
buildDropDown()
This function starts when our page is first loading. It's main task is to build our drop down menu and populate it with each city name from every event in our user's list. It does this by grabbing the whole list of events, then filtering it down to smaller lists based on information returned from the button. Then it asks more functions to complete their tasks and put all this information on the page.
getEventData()
getEventData() looks into the local storage of the user's browser and checks if they
have any event
information there. If it doesn't find anything, it sets it to the default event information we have.
displayStats()
displayStats() takes in our list of currentEvents and then calls upon our
four calculation functions to give it the values it needs to then put
the stats of each city's list of events at the overall stats section of our page, near the dropdown.
calcTotal()
calcTotal() is passed currentEvents and simply calculates the total amount
of attendees for either all or the city-filtered
events.
calcAverage()
calcAverage() is given currentEvents and totalAttendance then
calculates the average attendance of all or the city-filtered events.
calcMostAttended()
calcMostAttended() is passed currentEvents and then compares the
attendance amount of each event and gives us the highest amount.
calcLeastAttended()
calcLeastAttended is given currentEvents then it compares the attendance
amount of each event and gives us the
displayEventData()
displayEventData() is one of our major functions for displaying information onto the
page. It is given the currentEvents to work with. It grabs a template, or section of
HTML that we can use over and over, then for each of the events in our currentEvents it
uses the template to create a table row filled with the information of a single event =.
getEvents()
getEvents() is caleld upon by our different city buttons. It enables the filter for our
currentEvents list by grabbing the city name from the HTML element, then we ask if the
corresponding button name isn't "All" then it uses the city name retrieved and filters the
currentEvents based on the city name. It then also changes the header for our stats
spot,
changing it from "All Cities" to the name of the city the events took place in.
saveEventData()
Our final function,
saveEventData() is fairly important. It works with our 'Create Event'
button from the page. It reaches into each part of the form, takes the information the user has input
and then creates an object that is added to our event list. It then stores that in the local storage of
the browser, and updates the page to include the new event.