title: Implementing an upvote/downvote system in Javascript but can't get the math right
body: <pre><code>var $arrow       = $(this);
  var $sibling     = $arrow.siblings('span.arrow');
  var $score       = $arrow.siblings('span.score');
  
  var vote         = $arrow.hasClass('up') ? 'up' : 'down';
  var alreadyVoted = $sibling.hasClass('voted');
  
  if (!USER_LOGGED_IN)
  {
      alert('You must be logged into vote');
  }
  else if (!$arrow.hasClass('voted'))
  {
      if (alreadyVoted)
          $sibling.removeClass('voted');
  
      $arrow.addClass('voted');
      $score[0].innerHTML = parseInt($score[0].innerHTML) + ((vote == 'up') ? 1 : -1);
  }
  </code></pre>
  
  <p>I have an upvote and downvote button. A 'current score' is shown next to these buttons which I would like to increment/decrement when a vote is cast.</p>
  
  <p>For example, if they load the page and see the score is <code>200</code>. When they upvote, the score will change to <code>201</code>. When they downvote, the score needs to change to <code>199</code>. Why? Because if they downvote after upvotting (change their mind) then the vote needs to go from the original score. Not the new score they created by upvotting.</p>
  
  <p>Basically, if they upvote and then downvote, the score, currently, goes back to the original score. Their vote isn't cast.</p>
  
  <p>I'm having trouble making this work so their vote is cast...</p>