0

in the following function, I receive the correct PlayerID's but finalTotalNote is always 0. But why? I can't not see any mistake...

var finalSpielertemp = UserSpieler.find({UserID: 1}).map(function(doc) {
      return doc.SpielerID;
    });
    var distinctPlayer = _.uniq(finalSpielertemp, false);

    var d = 0;
    var finalRückgabe = ""
    while(distinctPlayer[d]){
      var spieltagDesSpielers = 0;
      UserSpieler.find({SpielerID: distinctPlayer[d]}).map(function(doc){
        spieltagDesSpielers = doc.SpieltagID;
      });

      var i = 0;
      var finalTotalNote = 0;
      while(spieltagDesSpielers[i]){
        var totalNote = 0;
        Spieltag.find({SpielerID: distinctPlayer[d], SpieltagID: spieltagDesSpielers[i]}).map(function (doc){
          totalNote += doc.Note;
        });

        finalTotalNote += totalNote;
        i++;
      }
      finalRückgabe += distinctPlayer[d] +" "+ finalTotalNote;
      d++;
    }
    return finalRückgabe;
HansMuff
  • 299
  • 1
  • 8
  • 22
  • Possible duplicate of [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – JJJ Apr 18 '17 at 16:39
  • I read this article but it is hard for me to change my code. Can you please give me a tip, what I have to change in my code? – HansMuff Apr 19 '17 at 14:44

0 Answers0