In this function, right after the first for loop, code isn't being reached. The alert("can't get here"); isn't working. Am I missing some obvious JavaScript caveat here?
The rest of the code can be found here: http://jsbin.com/tiweniludoqe/7/edit
Any help is much appreciated.
function checkForWin(){
var winCondition = 0;
//check for horizontal wins
for(i = 0; i < board[i].length; i++) {
for(j = 0; j < board[i].length; j++) {
winCondition += board[i][j];
if(winCondition === board[i].length) {
alert("win detected horizontal");
}
}
winCondition = 0;
}
alert("can't get here");
//check for vertical wins
for(i = 0; i < board[i].length; i++) {
for(j = 0; j < board[i].length; j++) {
winCondition += board[j][i];
alert("winCondition: " + winCondition);
if(winCondition === board[i].length) {
alert("win detected horizontal");
}
}
}
//if diagonal / is 3 or -3 win
//if diagonal \ is 3 or -3 win
}
Cannot read property 'length' of undefinedboard.lengthinstead ofboard[i].lengthiandjwithvarand useconsole.log()instead ofalert()