I'm trying to build a Weather app. I created an empty object to store certain data from the fetch response. Then in my fetch function I store the data in key/value pairs. When I console.log the weatherData variable it returns an object in my console but if I try to console.log a key/value of that object it returns undefined. Any idea why they are undefined? I've also tried
weatherData.hasOwnProperty('temp')
which returns false.
let weatherData = {};
function fetchWeather (city) {
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=72c205fe50ec0c81fbf1577dbf8e83f0&units=metric`)
.then(response => {
return response.json();
}).then(response => {
weatherData.temp = response.main.temp;
weatherData.feels_like = response.main.feels_like;
weatherData.humidity = response.main.humidity;
weatherData.wind = response.wind.speed;
weatherData.description = response.weather[0].description;
})
.catch(error => {
console.log(error);
});
};