2
I’m trying to get the tic-tac-toe to change the player who has the turn, I was able to change it from 'X' to 'O', but when I try to get back to 'X' and so on, it won’t.
Follow the code I made so far:
$(document).ready(function() {
$(".botao").click(function() {
$(this).text("X");
$("#jogador").text("É a vez do jogador 2");
mudarSimbolo();
});
function mudarSimbolo() {
if ($("#jogador").text() == "É a vez do jogador 2") {
$(".botao").click(function() {
$(this).text("O");
$("#jogador").text("É a vez do jogador 1");
});
} else if ($("#jogador").text() == "É a vez do jogador 1") {
$(".botao").click(function() {
$(this).text("X");
$("#jogador").text("É a vez do jogador 2");
});
}
}
});
.btn-default {
padding: 40px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" style="border:1px solid red; width:320px; height:320px;">
<button class="btn btn-default botao">1</button>
<button class="btn btn-default botao">2</button>
<button class="btn btn-default botao">1</button>
<button class="btn btn-default botao">2</button>
<button class="btn btn-default botao">3</button>
<button class="btn btn-default botao">4</button>
<button class="btn btn-default botao">5</button>
<button class="btn btn-default botao">6</button>
<button class="btn btn-default botao">7</button>
</div>
<div class="container">
<label id="jogador">É a vez do jogador 1</label>
</div>
We come to a similar solution :P if you want to remove mine ;]
– MarceloBoni
kk Keep yours there, it’s kind of different, it’s good to get the message that there are many ways to do it.
– Leonardo