I'm trying to make the game of the old one change the player who has the turn, I managed to make it change from 'X' to 'O', but when I try to return to 'X' and so on, it will not.
Follow the code I've 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><scriptsrc="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>