PLEASE help me, because JS is really killing me this time.
Everything was fine until I started to split my app into separate functions. Step one in my app is to get weather data. So I call getData function on window load. Response is fine, I get my data, I return them afterwards to the data variable. I console.log the data and array it is. But I can't acces array's values! Nor me nor some functions (d3.max() i.e.). I've tried everything but I have no clue what is going on.
(Hope the print screen will explain you the problem better)
window.onload = function(){
var data = getData( cities.poznan );
console.log(data);
console.log(data[0]);
}
var cities = {
poznan: "3088171",
madrid: "3117735",
barcelona: "3128760"
};
function round(n){
return Math.round( n * 10) / 10;
}
function getData(id){
var key = "22421a7c9d3efxxxxxx2b71394";
var url = "http://api.openweathermap.org/data/2.5/forecast/daily?id=" + id + "&units=metric&cnt=7&appid=" + key;
var data = [];
d3.json(url, function(response){
response.list.forEach(function(el){
data.push( el.temp.day );
});
});
return data;
}