I want to make a variable "city" global and use it in other function. I am requesting a JSON data and it seems to work in this function
var city;
function conditions(data) {
var city = data.current_observation.display_location.full;
var wcode = data.current_observation.icon;
$('#city').append('<h2>' +'Weather forecast in ' + city + '</h2>');
$('#city').addClass('headings-style');
}
But whe I try to use variable city in other function I'm getting an undefined data:
function forecastDays(info) {
var locationOne = info.forecast.simpleforecast.forecastday;
locationOne.forEach(function (daysPlus) {
var high = daysPlus.high.celsius;
var low = daysPlus.low.celsius;
var arr = ["day1", "day2", "day3", "day4"];
jQuery.each(arr, function (i, val) {
$("#temp_" + val).html('<p>' + city + 'High: ' + high + '°C' + '<br>' + ' Low: ' + low + '°C' + '</p>');
});
});
Please, help.
cityinsideconditions. Docity = ...instead ofvar city = ....