I'm new to NodeJS and I was trying to figure out stuff but unfortunately I couldn't find information on it with my knowledge.
Basicly, I want to use a variable from a function inside another function wich is a child of the main function.
Here is my code :
http.get(url, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var jsonResult = JSON.parse(body);
for (var i=0;i<5;i++)
{
gameId = jsonResult.gameList[i].gameId;
url = 'http://somesite.com/' + gameId + '/0/token';
http.get(url, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
jsonRes = JSON.parse(body);
switch(i)
{
case 0:
var elo0 = jsonRes.interestScore;
module.exports.elo0 = elo0;
break;
case 1:
var elo1 = jsonRes.interestScore;
module.exports.elo1 = elo1;
break;
case 2:
var elo2 = jsonRes.interestScore;
module.exports.elo2 = elo2;
break;
case 3:
var elo3 = jsonRes.interestScore;
module.exports.elo3 = elo3;
break;
case 4:
var elo4 = jsonRes.interestScore;
module.exports.elo4 = elo4;
break;
}
});
}).on('error', function(e) {
console.log("Got error: ", e);
});
}
});
}).on('error', function(e) {
console.log("Got error: ", e);
});
Note that I didn't include everything, just the problematic part. I want to use the variable i from the loop inside the switch but it doesn't work.