我正在尝试编写一个允许我选择棋盘上任何位置然后切换球员的功能。我试图写一个for循环但是没有出现任何东西或者所有的位置都填充了" X"。我相信一旦选择了一个位置,我就需要停止循环迭代,并为addEventLister创建另一个for循环。 (JS新手 - 谢谢!)
function player1(){
for(var i = 0; i<boardslots.length;i++) //Iterate through all the positions
if(boardSlots[i].classList !== "x" || "o"){ //Check to see if space is occupied
boardSlots[i].classList.add("x"); //Add X
player2(); //Switch to player 2
}
}
//Player 2 Selects O
function player2(){
for(var i = 0; i<boardslots.length;i++)
if(boardSlots[1].classList !== "x" || "o"){
boardSlots[1].classList.add("o");
player1();
}
}
boardSlots[i].addEventListener("click",player1); //Select Position on the board
答案 0 :(得分:0)
SuperClass does A.
SubClass does A.