I have 2 functions (setGame and loadScreen) that are related in the following way:
function setGame(user) {
ajaxCall to server script that returns "res"
as json object
console.log(res.data.status);
return res.data.status;
}
function loadScreen(user) {
var gameStatus = setGame(user);
if (gameStatus == 'WIN') {
doSomething();
console.log(gameStatus);
} else if (gametStatus == 'NOWIN') {
doSomeOtherStuff();
console.log(gameStatus);
} else
showError(gameStatus);
}
The question is:
Why if I print in console the value of gameStatus in loadScreen(user), I get alwasy UNDEFINED, but if I print it in setGame(user) it shows the exact value that I am expecting?
It looks like a "sequence of execution" issue or something I cannot get to.
Any hint? Thank you very much.