Project Link - https://codepen.io/zapbampow/pen/NwbOpO
I’ve run into an issue I haven’t been able to get around. If you go to my project and click through the options One Player -> Second Player -> Easy, the computer will take a turn. All the variables will change in order for the user to play, but then the user cannot play. If you choose First Player -> Easy the user can play continuously and the computer never takes a turn. I am 90% sure the issue is in the following function.
function easyOnePlayerGame() {
console.log("easyOnePlayerGame called.");
if (currentPlayerName === 'Computer') {
easyComputerTurn();
}
else {
playerTurn();
}
}
If I change the if…else to a while-loop, the computer takes a turn, then the user can play continuously without the computer being able to take another turn.
In psuedocode what I want to happen is this
if currentPlayerName is "Computer"
Computer takes a turn;
else
the user takes a turn;
I guess I’m just missing something for prompting the code to run the if-statement again. If I try to make the function recursive, it gets stuck in and infinite loop.
Any suggestions? I’m sure I’m missing something obvious.