(function onLoad() { // set a function for each button setButtonFunctions(); // fetch from each API when the page loads getLatestVideoData(); })(); function setButtonFunctions() { document.getElementById('covidNewConfirmed').onchange = function() { // display data const newConfirmed = document.getElementById('covidNewConfirmed').innerHTML; (resultData.download_url) ? newConfirmed.innerHTML = 'New confirmed cases: ' + resultData.download_url : newConfirmed.innerHTML = 'URL: 0'; lastUpdated.download_url = 'Last updated: ' + resultData.download_url; }; } // VIDEO URL async function getLatestVideoData() { await fetch("https://ХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХ", { "method": "GET", "headers": { "x-rapidapi-host": "ХХХХХХХХХХХХХХХХХХ", "x-rapidapi-key": "ХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХХ" } }) .then(response => response.json()) .then(response => { console.log(response); console.log(response.result.download_url); // save covid data to global variable Videodata = response.result.download_url; }) .catch(err => { console.log(err); }); }
URL: /