В чём заключается ошибка? server is not defined at HTMLAnchorElement.
Вот код программы
const weatherBlock = document.querySelector('#weather');
async function loadWeather(e){
weatherBlock.innerHTML = `
<div class="weather_loading">
<img src="./img/loading.gif" alt="Loading">
</div>
`;
var server = 'https://api.openweathermap.org/data/2.5/weather?&units=metric&q=Lviv&appid=574e986eeab53f684105869f71a44fe3';
const response = await fetch(server, {
method:'GET',
})
const responseResult = await response.json();
if(response.ok){
getWeather(responseResult)
}else{
weatherBlock.innerHTML = responseResult.message;
}
}
function getWeather(data){
console.log(data);
const location = data.name;
const temp = Math.round(data.main.temp);
const feelsLike = Math.round(data.main.feels_like);
const weatherStatus = data.weather[0].main;
const weatherIcon = data.weather[0].icon;
const template = `
<div class="weather_header">
<div class="weather_main">
<div class="weather_city">
${location}
</div>
<div class="weather_status">
${weatherStatus}
</div>
</div>
<!-- /weather_main -->
<div class="weather_icon">
<img src="https://openweathermap.org/img/w/${weatherIcon}.png" alt="CLouds">
</div>
<!-- /weather_icon -->
</div>
<!-- /weather_header -->
<div class="weather_temp">${temp}</div>
<div class="weather_feels-like">Feels like: ${feelsLike}</div>`;
weatherBlock.innerHTML = template;
const Lviv = document.querySelector('.Lviv');
const Kyiv = document.querySelector('.Kyiv');
const Warsaw = document.querySelector('.Warsaw');
Lviv.addEventListener('click', () =>{
server = 'https://api.openweathermap.org/data/2.5/weather?&units=metric&q=Lviv&appid=574e986eeab53f684105869f71a44fe3';
});
Kyiv.addEventListener('click', () =>{
server = 'https://api.openweathermap.org/data/2.5/weather?&units=metric&q=Kyiv&appid=574e986eeab53f684105869f71a44fe3';
})
Warsaw.addEventListener('click', () =>{
server = 'https://api.openweathermap.org/data/2.5/weather?&units=metric&q=Warsaw&appid=574e986eeab53f684105869f71a44fe3';
})
}
if(weatherBlock){
loadWeather();
}