А вот так?
cityName.addEventListener('keypress', function(e) {
if (e.keyCode == ENTER_KEY_CODE) {
var url = creatingUrl(cityName);
weather = query(url);
console.log(weather); //undefined
}
});
function query(theUrl) {
xhr.open('GET', theUrl);
xhr.send();
xhr.addEventListener('readystatechange', function() {
if (xhr.readyState != xhr.DONE) {
return;
}
if (xhr.status != 200) {
console.log('Error? Error!');
} else {
var serverAnswer = JSON.parse(xhr.responseText);
console.log(serverAnswer);
OtherWeatherData.style.display = 'block';
requestAccepted(serverAnswer);
return serverAnswer;
}
})
}