Skip to content

Commit

Permalink
with Restart button
Browse files Browse the repository at this point in the history
  • Loading branch information
SadeepaNHerath committed Aug 24, 2024
1 parent 59c711b commit 205923b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion vsComputer.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ <h1 class="display-3 text-warning">Tic-tac-toe <br> vs Computer </h1>
</tr>
</table>
</div>

<div class="d-flex justify-content-center align-items-center" style="margin: 30px;">
<button class="btn btn-outline-primary btn-lg" onclick="btnReloadClick()"> Restart </button>
</div>
</div>

<footer class="mt-auto bg-secondary text-light py-3">
Expand Down
12 changes: 8 additions & 4 deletions vsComputerApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ function computerTurn(){
return;
}, 600);
}
else if(emptyButtons.length == 0){
else if(emptyButtons == 0){
setTimeout(() => {
alert("Game Draw!");
window.location.reload();
return;
}, 600);
}
else{

}
currentPlayer = currentPlayer === "X" ? "O" : "X";
player.innerText = "Your Turn";
Expand All @@ -51,7 +51,6 @@ function btnClick(event) {
let clickedButton = event.target;

if (clickedButton.innerText === "") {
usedBtns.push(clickedButton.value);
clickedButton.innerText = "X";

if (
Expand All @@ -70,7 +69,7 @@ function btnClick(event) {
return;
}, 600);
}
else if(usedBtns.length == 9){
else if(buttonsArray.filter(button => button.innerText === "").length == 0){
setTimeout(() => {
alert("Game Draw!");
window.location.reload();
Expand All @@ -93,3 +92,8 @@ function btnClick(event) {
buttons.forEach(button => {
button.addEventListener('click', btnClick);
});

function btnReloadClick(){
location.reload();
return;
}
3 changes: 3 additions & 0 deletions vsPerson.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ <h1 class="display-3 text-warning">Tic-tac-toe <br> 1 Vs 1 </h1>
</table>
</div>

<div class="d-flex justify-content-center align-items-center" style="margin: 30px;">
<button class="btn btn-outline-primary btn-lg" onclick="btnReloadClick()"> Restart </button>
</div>
</div>

<footer class="mt-auto bg-secondary text-light py-3">
Expand Down
4 changes: 4 additions & 0 deletions vsPersonApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ buttons.forEach(button => {
button.addEventListener('click', btnClick);
});

function btnReloadClick(){
location.reload();
return;
}

0 comments on commit 205923b

Please sign in to comment.