Tic Tac Toe PDF
Tic Tac Toe PDF
HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic-Tac-Toe</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="msg-container hide">
<p id="msg">WINNER</p>
<button id="new-btn">New Game</button>
</div>
<main>
<h1>Tic-Tac-Toe</h1>
<div class="container">
<div class="game">
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
</div>
</div>
<button id="reset-btn">Reset Game</button>
</main>
<script src="app.js"></script>
</body>
</html>
CSS CODE
* {
margin: 0;
padding: 0;
}
body {
background-color: #548687;
text-align: center;
}
.container {
height: 70vh;
display: flex;
justify-content: center;
align-items: center;
}
.game {
height: 60vmin;
/*60% of viewport smaller dimension */
width: 60vmin;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 1.5vmin
}
.box {
height: 18vmin;
width: 18vmin;
border-radius: 1rem;
border: none;
box-shadow: 0 0 1 rem rgba(0, 0, 0, 0.3);
font-size: 8vmin;
color: #b0413e;
background-color: #ffffc7;
}
#reset-btn {
padding: 1rem;
font-size: 1.25rem;
background-color: #191913;
color: #fff;
border-radius: 1rem;
border: none;
}
#new-btn {
padding: 1rem;
font-size: 1.25rem;
background-color: #191913;
color: #fff;
border-radius: 1rem;
border: none;
}
#msg {
color: #ffffc7;
font-size: 5vmin;
}
.msg-container {
height: 100vmin;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 4rem;
}
.hide {
display: none;
}
.symbol-O {
color: black;
}
.symbol-X {
color: blue;
}
JAVASCRIPT CODE
boxes.forEach((box) => {
box.addEventListener("click", () => {
if (turnO) {
box.innerText = "O";
box.classList.add("symbol-O");
turnO = false;
} else {
box.innerText = "X";
box.classList.add("symbol-X");
turnO = true;
}
box.disabled = true;
checkWinner();
});
});
newGameBtn.addEventListener("click", resetGame);
resetbtn.addEventListener("click", resetGame);