I’m trying to get the value for row and col with the following function:
function find_winning_position(value, row, col) {
var i, j, chcount, emptycol, emptyrow;
chcount = 0;
emptycol = -1;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if (document.getElementById(elementArray[i][j]).innerHTML == value) {
chcount++;
}
else if (document.getElementById(elementArray[i][j]).innerHTML.length == 0) {
emptycol = j;
}
}
if (chcount == 2 && emptycol != -1) {
row = i;
col = emptycol;
return row;
return col;
}
}
}
how to get it? what am doing wrong here… can anyone explain?
var row = -1,
col = -1;
find_winning_position("O", row, col);
alert("row value" + row);
alert("col value" + col);
if (row != -1 && col != -1) {
//do some thing here
}
What am I doing wrong here?
The first problem is that you are trying to
returnwhen you have alreadyreturned.The second problem is that you don’t assign the return value of the function to anything.
and
You also need to cope with the situation where the function doesn’t return anything (since all your returns are inside an if statement).