When a user clicks on the button, a function gets called. Inside the function is a fetch request that will detect where you are at and then return the flag and data from that country. If you are based in the US, it will return that flag. If you are in Italy, it will return that flag.
This app uses the fetch api and promises to handle the resolve and rejection for the api requests. Specifically there are nested apis that first use the geolocation api to figure out where you are, then passes that data to the GEOCODE API to do reverse geocoding. This takes the latitude and longitude and uses it to find the location data. Then finally that data is fed to the RESTCountries API to find the country so it can render a flag with data in the UI.
This is the original way I did the whereAmI function without using the geolocation api and used the getJSON function to do the repeatable fetch function.