My coding is as follows:
var data = JSON.parse(http.responseText);
var weatherData = new Weather(cityName, data);
weatherData.temperature = data.main.temp;
updateWeather(weatherData);
function Weather(cityName, data) {
this.cityName = cityName
data.weather[0].description = descriptions;
this._temperature = '';
}
function updateWeather(weatherData) {
weatherCity.textContent = weatherData.cityName;
weatherDescription.textContent = weatherData.descriptions;
weatherTemperature.textContent = weatherData.temperature;
loadingText.style.display = 'none';
weather.style.display = 'block';
I encountered an error stating that "descriptions is not defined". The code works fine if I make the following adjustment:
var data = JSON.parse(http.responseText);
var weatherData = new Weather(cityName, data.weather[0].description);
weatherData.temperature = data.main.temp;
updateWeather(weatherData);
function Weather(cityName, description) {
this.cityName = cityName
this.description = descriptions;
this._temperature = '';
}
function updateWeather(weatherData) {
weatherCity.textContent = weatherData.cityName;
weatherDescription.textContent = weatherData.descriptions;
weatherTemperature.textContent = weatherData.temperature;
loadingText.style.display = 'none';
weather.style.display = 'block';
I am unsure about what to do now. Could it be that I am not receiving a value back? If someone could provide a fix so that I can understand better, that would be greatly appreciated. I am fairly new to this, so please excuse any naive questions. I was attempting the first method because I have additional information like weather pressure, wind speed, sunrise, etc., that I want to incorporate.