In trying to just fetch from the api once, I moved the fetchData() function to the top. The function renamed to createData() now fetches the dinosaurs from the api as well as creating the data needed for the Map and Diet Tools. The data is put into global variables that we can use later in app.js. The new variables are
allDinosaurs - an array of all dinosaur objects
dinosaursPerCountry - an object that holds the number of dinosaurs found in each country
dietData - an array that holds a diet object for each time period
As long as functions in app.js aren't called before the createData() function finishes, there aren't problems with the data not being there yet. For example onSearch() and showCountryInfo() are in eventListeners. I will need to make sure any function that needs the dietData isn't called until the fetch has occurred as well.
In trying to just fetch from the api once, I moved the fetchData() function to the top. The function renamed to createData() now fetches the dinosaurs from the api as well as creating the data needed for the Map and Diet Tools. The data is put into global variables that we can use later in app.js. The new variables are
allDinosaurs - an array of all dinosaur objects dinosaursPerCountry - an object that holds the number of dinosaurs found in each country dietData - an array that holds a diet object for each time period
As long as functions in app.js aren't called before the createData() function finishes, there aren't problems with the data not being there yet. For example onSearch() and showCountryInfo() are in eventListeners. I will need to make sure any function that needs the dietData isn't called until the fetch has occurred as well.