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
1 comments On Bài tập game vui(làm theo cách mình hiểu một cách đơn giản nhất, dễ nhất)
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.