0

So I calculate the variable winningDecision and print to console - this comes out correct.

I then try to push winningDecision into another Array (winDecide). When I console winDecide, the result is not correct. If winningDecision is "draw" for example, "player" gets pushed.

Any explanation would be really helpful.

for (var k =0;k<dealerScoreHolder.length;k++)
{
        
    var winningDecision = JSON.parse(JSON.stringify(winnerCalc(playerPossibilities[i][1],dealerScoreHolder[k][2])));
        console.log(winningDecision);
    
        winDecide.push([winningDecision,dealerScoreHolder[k][0]]);
    
       console.log(winDecide);
    
        
        if(winDecide[k][0]="player")
            {chancesWin[0]+=winDecide[k][1] 
            }
        else if (winDecide[k][0]="draw")
            {chancesWin[1]+=winDecide[k][1] 
            }
        else if (winDecide[k][0]="dealer")
            {chancesWin[2]+=winDecide[k][1]
            }
        console.log(chancesWin);
      
       debugger;
 }
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
HarryShotta
  • 347
  • 1
  • 15
  • 4
    `JSON.parse(JSON.stringify(...))` *can* be useful in certain weird situations, but I really doubt this is one of them. – Pointy Apr 05 '19 at 13:54
  • 1
    Can you put the excepted result and received result into your post? Also an example how winningDecision looks. – Wimanicesir Apr 05 '19 at 13:55
  • 4
    All of your if statements use `=` instead of `==` or `===` for comparison, so they won't work. – Pointy Apr 05 '19 at 13:56
  • well spotted - the ===. That's one error out of the way. Still doesn't explain my initial problem though.... scratch that it is working now. Thanks for your help! – HarryShotta Apr 05 '19 at 14:03

0 Answers0