title: how variable scope works in jquery?
body: <pre><code>var change = 1;
  
  $("#game").click(function (e) {
      if (change == 1) {
          var data = $(e.target).closest("td").text();
          var p1 = $("#player1").val();
          var p1_value = p1 + data;
          $("#player1").val(p1_value);
          change = 2;
      } else(change == 2) {
          var data = $(e.target).closest("td").text();
          var p2 = $("#player2").val();
          var p2_value = p2 + data;
          $("#player2").val(p1_value);
          change = 1;
      }
  
  });
  </code></pre>
  
  <p>Is it the write way to write? BTW here it is not going to the else loop.</p>