I'm having trouble getting the value of a variable I calculate elsewhere to work in another function. I know I'm missing something obvious, but not sure what. Here's what my code looks like:
var total_count;
function getDistances() {
$.getJSON('https://something.com', function(data){
var total_count = data.rows[0].count; //this is the correct value for total_count
});
$.getJSON('https://anotherthing.com', function(data){
d1_1 = [];
var limit = 4;
$.each(data.rows, function(index, item){
if(index > limit)
return false;
console.log(total_count); //This is undefined
d1_1.push([Math.round((item.count/total_count*100)*100)/100,index]);
//because total_count is undefined here, I get NaNs
});
});