I've been trying to figure this problem out for hours but I'm having absolutely no luck.
The programs runs through the first iteration without any issues (numbers are spliced into the array properly and the results are printed to console perfectly) but on the second run I get this error:
Uncaught TypeError: Cannot call method 'splice' of undefined
Nothing at all is printed to the console log at this point.
Here's the first function:
var gameRound = [
[],
[]
];
fight();
function fight() {
var r = 10;
var towel = false;
var i = 1;
while (i <= r && towel == false) {
round(i);
console.log("ROUND ", i);
console.log(boxerA[0]);
console.log("Punches Thrown: ", gameRound[i][0]);
console.log("Punches Landed: ", gameRound[i][1]);
console.log("Jabs Thrown: ", gameRound[i][2]);
console.log("Jabs Landed: ", gameRound[i][3]);
console.log("Power Thrown: ", gameRound[i][4]);
console.log("Power Landed: ", gameRound[i][5]);
console.log("Fatigue: ", boxerA[28]);
console.log("Damage: ", boxerA[29]);
console.log(boxerB[0]);
console.log("Punches Thrown: ", gameRound[i][6]);
console.log("Punches Landed: ", gameRound[i][7]);
console.log("Jabs Thrown: ", gameRound[i][7]);
console.log("Jabs Landed: ", gameRound[i][9]);
console.log("Power Thrown: ", gameRound[i][10]);
console.log("Power Landed: ", gameRound[i][11]);
console.log("Fatigue: ", boxerB[28]);
console.log("Damage: ", boxerB[29]);
i++;
}
}
And the function and line where I get the error listed:
function round(i)
{
// ...
gameRound[i].splice(0,0,numPunchesTA,numPunchesLA,numJabsTA,numJabsLA,numPowerTA, numPowerLA, numPunchesTB, numPunchesLB,numJabsTB,numJabsLB,numPowerTB,numPowerLB);
}
When I test it the variable i is still counted up to "2" so I'm not sure why the next row isn't being spliced into the array.