I am working on a game board where I need to replace arrays with new ones that have changes in specific spots.
Here is the initial game board structure:
var gameBoard = [
["-","-","-","-","-","-"],
["-","-","-","-","-","-"],
["-","-","-","-","-","-"],
["-","-","-","-","-","-"],
["-","-","-","-","-","-"],
["-","-","-","-","-","-"]
];
Players can choose their attack spot using prompts:
var playerChoiceRow = prompt("Please select row of attack. (0 through 5)") - "";
var playerChoiceColumn = prompt("Please select column of attack. (0 through 5)") - "";
However, there seems to be an issue with the attack function that only outputs an array of "X"s instead of updating the chosen spot correctly.
function attack(playerChoiceRow, playerChoiceColumn) {
var array = [];
for (i = 0; i < gameBoard.length; i++){
if (array[i] === playerChoiceColumn) {
array[i] = "X";
} else {
array[i] = "-";
}
}
console.log(array);
}
console.log(gameBoard);
attack();