I'm really stuck with what maybe a scoping issue. Can anyone here please help me find fault with this snippet?
So I have something called surveys that are associated with a questiongroup. And i'm trying to loop through surveys to get data about the associated questiongroup except I'm really lost on where I should scope a question group.
The first function in snippet below logs qg as 'undefined' returned from the second function.
function loadData() {
var params = {};
var surveyURL = "surveys/";
var surveys, qg;
var survey_ids = [];
// this below calls the URL
var $surveyXHR = klp.api.do(surveyURL, params);
// this below is essentially $.ajax.done()
$surveyXHR.done(function(data) {
surveys = data["features"];
for(var each in surveys) {
qg = getSurveysQuestionGroup(surveys[each]["id"]);
console.log(qg);
// surveys[each]["created_by"] = qg["created_by"]["first_name"]
}
console.log(surveys);
});
}
function getSurveysQuestionGroup (surveyId) {
var params = {};
var qg;
var qgURL = "surveys/"+ surveyId + "/questiongroups/";
var $qgXHR = klp.api.do(qgURL, params);
$qgXHR.done(function(data) {
qg= data["features"];
//console.log(qg);
return(qg);
});
}