I tried to use getValue() on the row[column]
to get the value of a row-column wise in my gameboard array depending on the conditon stated below so as to get all the empty cells using filter and map method on the array into variable called availableCells, but this error showed up. any help will be appreciated
// create a gamebaord array and store within a Gameboard object within a function.
const Gameboard = function () {
const rows = 3;
const columns = 3;
const gameboard = [];
//Create a 2d-array
for(i = 0; i < rows; i++) {
gameboard[i] = [];
for(j = 0; j < columns; j++) {
gameboard[i][j] = j;
}
}
// This what the UI will use to render the board.
const getBoard = () => gameboard;
console.log(getBoard());
// Create a dropmarker function to add player marker to the board.
const dropMarker = (column, player) => {
//filter the gamebaord array and store the empty cells into the availableCells variable decleared.
const availableCells = gameboard.filter((row) => row[column].getValue() === 0).map(row => row[column]);
console.log(availableCells);
// const mapAvailableCells = availableCells.map(row => row[column]);
// console.log(mapAvailableCells);
// if there is no emptyCell, stop the execution
if(!availableCells.length) return;
const lowestRow = availableCells.length - 1;
gameboard[lowestRow][column].addMarker(player);
};
dropMarker();
return { getBoard } ;
}
console.log(Gameboard());
New contributor
Bright Anyawe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.