code

The code is structured in seven functions:


buildDropdown()

This function retrieves the event data from the events array and maps each unique city to an item on the dropdown button. It then uses the information from the objects inside events to populate the table with information. Next, currentEvents, which is a variable storing the results of getEventData() gets passed to the next function:


displayStats()

This function begins by calling the next function, calculateStats(), to get the stats and then display them. It also converts the numbers in the stats to have the correct regional formatting.


calculateStats()

This function takes in the values from eventArray and calculates minimum, maximum, average, and total values for each event. It then passes these values back to displayStats().


displayEventData()

This function is similar to displayStats(), except it displays all the values from all of the objects on a large table at the bottom of the page using a for loop and an HTML template.


getEventData()

This function simply ensures the currentEvents() array contains some data. If currentEvents() is empty, events is passed into the array.


getEvents()

This function determines which set of data to display on the large table. If the currently selected dropdown list item is not 'All', then it filters the table by whatever the currently selected city actually is.


saveEventData()

This function retrieves user data from the 'new event' modal and adds it to an object newEvent. This object is then passed into currentEvents and buildDropdown() is reloaded to include any new city names.