This has me a little stumped. Whenever I execute this code, if one of the if
statements in the for
loop are true, all three sub-arrays of weaknessArray
get effected. The same thing happens when each if
statement is in it's own for
loop and if instead of one 2D array I use a three separate arrays, one for each for
loop.
var typeChart = [2,2,2,2,2,2,4,2,2,2,2,2,2,0,2,2,2,2];
var blankArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var weaknessArray = [blankArray,blankArray,blankArray];
for(i = 0; i<18; i++){
if(typeChart[i] === 0) weaknessArray[2][i] = 1;
if(typeChart[i] === 1) weaknessArray[1][i] = 1;
if(typeChart[i] === 4) weaknessArray[0][i] = 1;
console.log(weaknessArray);
}
Aucun commentaire:
Enregistrer un commentaire