hopefully someone will be able to help me solve this issue that I'm dealing with. I am trying to return a function inside a function but my code seems not to work... using Javascript. Here is my code :
function chosenPiece() {
if (isWhite) {
for (let i = 0; i < 12; i++) {
whitePiecesList[i].addEventListener("click", function findPositionOnBoard(event) {
for (let i = 0; i < boardCellsList.length; i++) {
if (boardCellsList[i].firstElementChild === event.target) {
let position = i;
return position;
}
}
});
}
} else {
for (let i = 0; i < 12; i++) {
blackPiecesList[i].addEventListener("click", function findPositionOnBoard(event) {
for (let i = 0; i < boardCellsList.length; i++) {
if (boardCellsList[i].firstElementChild === event.target) {
let position = i;
return position;
}
}
});
}
}
return findPositionOnBoard();
}
Can someone identify the problem? Thanks!