title: Basic math issue in JavaScript/jQuery - Variable remembering value?
body: <p>I have a button that, for example, has a number 3 on it.  If user presses it, it goes to 4.  If they press again, it should go BACK to 3.  Instead, it goes to 2.  The problem is that when I'm trying to set the main variable with the new total, it is not saving the value.  Can someone see what is happening?</p>
  
  <p>Here is jQuery/JS:</p>
  
  <pre><code>    var $this = $(this),
      was_voted = $this.data('wasvoted'),
      vote_total = $this.data('vote_total');
      $.ajax({
          // edited
          },
  
          success : function(data) {
  
  
              if (was_voted == 1) {
                  $this.vote_total = vote_total - 1;
                  $this.data('wasvoted', 0);
              } else if (was_voted == 0) {
                  $this.vote_total = vote_total + 1;
                  $this.data('wasvoted', 1);
              }
  
              vote_total = $this.vote_total;
  
              $this.find('.vote_total').text($this.vote_total);
  
          }
      });
  </code></pre>