title: Changing value of a variable within an if statement in Javascript
body: <p>I'm having a problem with a piece of code and it's driving me nuts. I've been stuck on this for hours, and the worst part is that I'm assuming it's really simple; I just can't figure it out.</p>
  
  <p>I'm trying to make a simple event calendar using Javascript/jQuery. This is the simplified code that I have:</p>
  
  <pre><code>var currentMonth = 1;
  if (currentMonth == 1) {
      $("#prev-month").click( function() {
          currentMonth = 12;
      });
      $("#next-month").click( function() {
          currentMonth = 2;
      });
  }
  if ( currentMonth == 2) {
      $("#prev-month").click( function() {
          currentMonth = 1;
      });
      $("#next-month").click( function() {
          currentMonth = 3;
      });
  }
  if ( currentMonth == 3) {
      $("#prev-month").click( function() {
          currentMonth = 2;
      });
      $("#next-month").click( function() {
          currentMonth = 4;
      });
  }
  if ( currentMonth == 4) {
      $("#prev-month").click( function() {
          currentMonth = 3;
      });
      $("#next-month").click( function() {
          currentMonth = 5;
      });
  }
  </code></pre>
  
  <p>Now, every time I click the button with the ID "next-month", it is always 2. If I click the button with the ID "prev-month", it is always 12. It never changes. What am I doing wrong?</p>