function requestWeatherData() {
    var http, key, url, method, cityInput, cityInputMedia, content, loader, error;

    content = document.querySelector('.container__display');
    loader = document.getElementById('loader');
    error = document.getElementById('error');

    loader.style.display = 'block';
    content.style.display = 'none';

    cityInput = document.getElementById('city').value;
    cityInputMedia = document.getElementById('city-small').value;
    toggleVisibility('.toggle-display', 'visible');

    function isHidden(el) {
        return (el.offsetParent === null)
    }

    http = new XMLHttpRequest();
    key = 'f7ae93273991702a76175c327cf35188';
    method = 'GET';
    
    var cityValue;
    
    //function which distinguish from which input data must be read
    function generateAPIKey(input) {
        if (input.trim().length === 0) {
            toggleVisibility('.toggle-display', 'hidden');
            loader.style.display = 'none';
            error.style.display = 'block';
            error.textContent = 'Please enter City Name!';
        } else {
            error.style.display = 'none';
            
            url = 'http://api.openweathermap.org/data/2.5/weather?q=' + input + '&units=metric&appid=' + key;
            cityValue = input;
        }
        var data = {url: url, cityValue: cityValue};
        
        return data;
    }
    
    var data;
    if (!isHidden(document.getElementById('city'))) {
        data = generateAPIKey(cityInput);
    } else if (!isHidden(document.getElementById('city-small'))) {
        data = generateAPIKey(cityInputMedia);
    }
    
    var cityValue = data.cityValue;
    
    //Opening connection
    http.open(method, data.url);
    
    //Callback is called from the user interface. Readystatechange is fired every time the readyState property of request changes.
    http.onreadystatechange = function () {
        if (http.readyState === 4 && http.status === 200) {
            var data = JSON.parse(http.responseText);
            var weatherObj = fetchData(data);
            var weatherData = new Weather(
                cityValue,
                weatherObj.desc,
                (weatherObj.temp).toFixed(0),
                weatherObj.humid,
                weatherObj.wind,
                weatherObj.pressure);

            weatherUI(weatherData);
            loader.style.display = 'none';
            content.style.display = 'flex';

            showWeatherIcon();

        } else if (http.readyState === 4) {
            return
        }
    }

    //Sending request to the server
    http.send();

    document.querySelector('#city').value = '';
    document.querySelector('#city').focus();
}
//Function which get HTTP requests and processes. Result of this operation is JSON object downloaded from https://openweathermap.org/api
Function which get HTTP requests and processes.
Function which get HTTP requests and processes .
function requestWeatherData() {
    var http, key, url, method, cityInput, cityInputMedia, content, loader, error;
    content = document.querySelector('.container__display');
    loader = document.getElementById('loader');
    error = document.getElementById('error');
    loader.style.display = 'block';
    content.style.display = 'none';
    cityInput = document.getElementById('city').value;
    cityInputMedia = document.getElementById('city-small').value;
    toggleVisibility('.toggle-display', 'visible');
    function isHidden(el) {
        return (el.offsetParent === null)
    }
    http = new XMLHttpRequest();
    key = 'f7ae93273991702a76175c327cf35188';
    method = 'GET';
    var cityValue;
    function generateAPIKey(input) {
        if (input.trim().length === 0) {
            toggleVisibility('.toggle-display', 'hidden');
            loader.style.display = 'none';
            error.style.display = 'block';
            error.textContent = 'Please enter City Name!';
        } else {
            error.style.display = 'none';
            url = 'http://api.openweathermap.org/data/2.5/weather?q=' + input + '&units=metric&appid=' + key;
            cityValue = input;
        }
        var data = {url: url, cityValue: cityValue};
        return data;
    }
    var data;
    if (!isHidden(document.getElementById('city'))) {
        data = generateAPIKey(cityInput);
    } else if (!isHidden(document.getElementById('city-small'))) {
        data = generateAPIKey(cityInputMedia);
    }
    var cityValue = data.cityValue;
    http.open(method, data.url);
    http.onreadystatechange = function () {
        if (http.readyState === 4 && http.status === 200) {
            var data = JSON.parse(http.responseText);
            var weatherObj = fetchData(data);
            var weatherData = new Weather(
                cityValue,
                weatherObj.desc,
                (weatherObj.temp).toFixed(0),
                weatherObj.humid,
                weatherObj.wind,
                weatherObj.pressure);
            weatherUI(weatherData);
            loader.style.display = 'none';
            content.style.display = 'flex';
            showWeatherIcon();
        } else if (http.readyState === 4) {
            return
        }
    }
    http.send();
    document.querySelector('#city').value = '';
    document.querySelector('#city').focus();
}
function requestWeatherData ( ) { var http , key , url , method , cityInput , cityInputMedia , content , loader , error ; content = document . querySelector ( '.container__display' ) ; loader = document . getElementById ( 'loader' ) ; error = document . getElementById ( 'error' ) ; loader . style . display = 'block' ; content . style . display = 'none' ; cityInput = document . getElementById ( 'city' ) . value ; cityInputMedia = document . getElementById ( 'city-small' ) . value ; toggleVisibility ( '.toggle-display' , 'visible' ) ; function isHidden ( el ) { return ( el . offsetParent === null ) } http = new XMLHttpRequest ( ) ; key = 'f7ae93273991702a76175c327cf35188' ; method = 'GET' ; var cityValue ; function generateAPIKey ( input ) { if ( input . trim ( ) . length === 0 ) { toggleVisibility ( '.toggle-display' , 'hidden' ) ; loader . style . display = 'none' ; error . style . display = 'block' ; error . textContent = 'Please enter City Name!' ; } else { error . style . display = 'none' ; url = 'http://api.openweathermap.org/data/2.5/weather?q=' + input + '&units=metric&appid=' + key ; cityValue = input ; } var data = { url : url , cityValue : cityValue } ; return data ; } var data ; if ( ! isHidden ( document . getElementById ( 'city' ) ) ) { data = generateAPIKey ( cityInput ) ; } else if ( ! isHidden ( document . getElementById ( 'city-small' ) ) ) { data = generateAPIKey ( cityInputMedia ) ; } var cityValue = data . cityValue ; http . open ( method , data . url ) ; http . onreadystatechange = function ( ) { if ( http . readyState === 4 && http . status === 200 ) { var data = JSON . parse ( http . responseText ) ; var weatherObj = fetchData ( data ) ; var weatherData = new Weather ( cityValue , weatherObj . desc , ( weatherObj . temp ) . toFixed ( 0 ) , weatherObj . humid , weatherObj . wind , weatherObj . pressure ) ; weatherUI ( weatherData ) ; loader . style . display = 'none' ; content . style . display = 'flex' ; showWeatherIcon ( ) ; } else if ( http . readyState === 4 ) { return } } http . send ( ) ; document . querySelector ( '#city' ) . value = '' ; document . querySelector ( '#city' ) . focus ( ) ; }
Function which get HTTP requests and processes.
Function which get HTTP requests and processes .
//function which distinguish from which input data must be read //Opening connection //Callback is called from the user interface. Readystatechange is fired every time the readyState property of request changes. //Sending request to the server