let board = [];
let max = +prompt("nhập số ô muốn chơi (ex: 9x9)",15);
let turn = 1;
for (let i = 0; i < max; i++) {
board.push([]);
for (let j=0;j<max;j++){
board[i].push(' ');
}
}
document.write("<table border='1'>");
for(let i =0; i<max; i++){
document.write("<tr>");
for(let j=0; j<max; j++){
document.write('<td onclick="change(this)" style="width: 25px;height: 25px;text-align: center">');
document.write(board[i][j]);
document.write('</td>');
}
document.write("</tr>");
}
document.write('</table>');
function change(td){
if(td.innerHTML===' '){
if(turn === 1){
td.innerHTML = "X";
turn = 0
}else {
td.innerHTML = "O";
turn = 1
}
}
}
Related