lct_script.js
// Obtain initial country data from API
Obtain initial country data from API
Obtain initial country data from API
function init_country_data() {
    $('form').on('submit', function(event) {
        event.preventDefault();
        var $input = $(this).find('input');
        input = $input.val();
        $('#text-output').text(input);
        $.get('https://corona.lmao.ninja/v2/countries/' + input, function(data) {
            if (input == '') {
                $("#country_cases").text('*** PLEASE ENTER A COUNTRY ***');
                $("#country_today_cases").text('');
                $("#country_deaths").text('');
                $("#country_today_deaths").text('');
                $("#country_recovered").text('');
                $("#country_active").text('');
                $("#country_critical").text('');
                $("#country_cases_per_one_million").text('');
                $("#country_deaths_per_one_million").text('');
                $("#country_tests").text('');
                $("#country_tests_per_one_million").text('');
            } else if (data == "Country not found or doesn't have any cases") {
                $("#country_today_cases").text('');
                $("#country_deaths").text('');
                $("#country_today_deaths").text('');
                $("#country_recovered").text('');
                $("#country_active").text('');
                $("#country_critical").text('');
                $("#country_cases_per_one_million").text('');
                $("#country_deaths_per_one_million").text('');
                $("#country_tests").text('');
                $("#country_tests_per_one_million").text('');
            } else {
                $("#country_cases").text(data.cases + ' Cases');
                $("#country_today_cases").text(data.todayCases + ' Cases Today');
                $("#country_deaths").text(data.deaths + ' Deaths');
                $("#country_today_deaths").text(data.todayDeaths + ' Deaths Today');
                $("#country_recovered").text(data.recovered + ' Recovered');
                $("#country_active").text(data.active + ' Active');
                $("#country_critical").text(data.critical + ' Critical');
                $("#country_cases_per_one_million").text(data.casesPerOneMillion + ' Cases Per One Million');
                $("#country_deaths_per_one_million").text(data.deathsPerOneMillion + ' Deaths Per One Million');
                $("#country_tests").text(data.tests + ' Tests');
                $("#country_tests_per_one_million").text(data.testsPerOneMillion + ' Tests Per One Million');
            }
        });
        setInterval("country_data()", 60000);
    });	
}
function init_country_data ( ) { $ ( 'form' ) . on ( 'submit' , function ( event ) { event . preventDefault ( ) ; var $input = $ ( this ) . find ( 'input' ) ; input = $input . val ( ) ; $ ( '#text-output' ) . text ( input ) ; $ . get ( 'https://corona.lmao.ninja/v2/countries/' + input , function ( data ) { if ( input == '' ) { $ ( "#country_cases" ) . text ( '*** PLEASE ENTER A COUNTRY ***' ) ; $ ( "#country_today_cases" ) . text ( '' ) ; $ ( "#country_deaths" ) . text ( '' ) ; $ ( "#country_today_deaths" ) . text ( '' ) ; $ ( "#country_recovered" ) . text ( '' ) ; $ ( "#country_active" ) . text ( '' ) ; $ ( "#country_critical" ) . text ( '' ) ; $ ( "#country_cases_per_one_million" ) . text ( '' ) ; $ ( "#country_deaths_per_one_million" ) . text ( '' ) ; $ ( "#country_tests" ) . text ( '' ) ; $ ( "#country_tests_per_one_million" ) . text ( '' ) ; } else if ( data == "Country not found or doesn't have any cases" ) { $ ( "#country_today_cases" ) . text ( '' ) ; $ ( "#country_deaths" ) . text ( '' ) ; $ ( "#country_today_deaths" ) . text ( '' ) ; $ ( "#country_recovered" ) . text ( '' ) ; $ ( "#country_active" ) . text ( '' ) ; $ ( "#country_critical" ) . text ( '' ) ; $ ( "#country_cases_per_one_million" ) . text ( '' ) ; $ ( "#country_deaths_per_one_million" ) . text ( '' ) ; $ ( "#country_tests" ) . text ( '' ) ; $ ( "#country_tests_per_one_million" ) . text ( '' ) ; } else { $ ( "#country_cases" ) . text ( data . cases + ' Cases' ) ; $ ( "#country_today_cases" ) . text ( data . todayCases + ' Cases Today' ) ; $ ( "#country_deaths" ) . text ( data . deaths + ' Deaths' ) ; $ ( "#country_today_deaths" ) . text ( data . todayDeaths + ' Deaths Today' ) ; $ ( "#country_recovered" ) . text ( data . recovered + ' Recovered' ) ; $ ( "#country_active" ) . text ( data . active + ' Active' ) ; $ ( "#country_critical" ) . text ( data . critical + ' Critical' ) ; $ ( "#country_cases_per_one_million" ) . text ( data . casesPerOneMillion + ' Cases Per One Million' ) ; $ ( "#country_deaths_per_one_million" ) . text ( data . deathsPerOneMillion + ' Deaths Per One Million' ) ; $ ( "#country_tests" ) . text ( data . tests + ' Tests' ) ; $ ( "#country_tests_per_one_million" ) . text ( data . testsPerOneMillion + ' Tests Per One Million' ) ; } } ) ; setInterval ( "country_data()" , 60000 ) ; } ) ; }
Obtain initial country data from API
Obtain initial country data from API
// console.log(data); // Check API every 60 seconds