title: randomizing number again if statement was false JavaScript
body: <pre><code>function computerLogic(array) {
  
      function random() {
          var rand = Math.floor(Math.random() * 9);
          if ((array[rand] === playerChoice) || (array[rand] === computerChoice)) {
              random(); &lt; ----------------------- THATS MY PROBLEM,
          } else if (array[rand] === 0) {
              array[rand] = computerChoice;
              grid.item(rand).innerHTML = computerChoice;
          } else {
              alert("END OF THE GAME!");
              console.log(array[rand]);
          }
      }
      random();
  
  }
  </code></pre>
  
  <p>so its part of my Tic Tac Toe code to put O or X to the grid.
  This function is being called in function handling clicks of users.Every time user clicks something then this function is called and updated array is send to it.</p>
  
  <p>Im recursively calling function random() to random again number if it is in range of if statement.</p>
  
  <p>I dont want to call it recursively but I have no idea how to make var rand to random again instead of calling whole random() function again.</p>
  
  <p>just ignore last else statement.</p>
  
  <p>here you can look at all code if its chaotic for you. 
  <a href="https://github.com/uRTLy/Tic-Tac-Toe" rel="nofollow">https://github.com/uRTLy/Tic-Tac-Toe</a></p>
  
  <p>EDIT</p>
  
  <pre><code>function computerLogic(array) {
  
   function random() {
  
  var rand = Math.floor(Math.random() * 9);
  
  
  
  var result = (array[rand] === computerChoice) || (array[rand] === playerChoice) ?
    random(): (function(rand) {
      array[rand] = computerChoice;
      grid.item(rand).innerHTML = computerChoice;
    })(rand);
  }
  
  random();
  
  
   }
  </code></pre>
  
  <p>done it like this also but still exceeds stack size and still does the same as earlier.</p>