我的第三個else語句條件應該是for循環的結果。我如何使用循環的條件?對else語句中的條件使用for循環語句的結果
//If player clicks centre on first move go in corner square
if (current[4] === playerToken && this.state.stepNumber === 1) {
let move = cornerSquares[Math.floor(Math.random() * cornerSquares.length)];
drawSquare(move);
}
//If player clicks corner square on first move go in centre square
else if (this.state.stepNumber === 1) {
for (let i = 0; i < cornerSquares.length; i++){
if (current[cornerSquares[i]] === playerToken) {
drawSquare(4);
}
}
}
//If player or computer has 2 in a row, place in 3rd square to win or block
else if (/*CONDITION OF THE BELOW FOR LOOP*/) {
for (let i = 0; i < twoInRow.length; i++) {
const [a, b, c] = twoInRow[i];
if (current[a] && current[a] === current[b]) {
drawSquare(c);
}
}
}
//Place in random empty square
else {
//code to randomly place x/o in random square
}
}
謝謝,我的序列中有太多趕上了 - 含多處如果陳述工作正常:) – Nims