I made a simple version of the game tic tac toe. When you click on a cell, a cross appears in it and a function is called to put a zero randomly.
I added the condition that if the cell is not empty, then put nothing. With a cross it works, but with zero. If the cell is busy, then it does not put anything at all. How can I fix this normally?
$(function() { var bot = function() { var cell = Math.floor(Math.random() * (10 - 1)) + 1; if( $('.board-cell').eq(cell).text() == '' ) $('.board-cell').eq(cell).text( 'O' ); }; $('.board-cell').click(function() { if( $(this).text() == '' ){ $(this).text( 'X' ); bot(); }; }); }); .board { display: flex; flex-wrap: wrap; width: 153px; height: 153px; border-left: 1px solid black; border-top: 1px solid black; } .board-cell { width: 50px; height: 50px; border-right: 1px solid black; border-bottom: 1px solid black; cursor: pointer; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="board"> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> <div class="board-cell"></div> </div>