title: Problem keeping variable alive in a javascript function
body: <p>I want to house a variable in a function. This variable will change state depending on user interaction. For example:</p>
  <pre><code>function plan_state(current){
      if (current != ''){
          state = current;
      }
      else {
          return state;
      }
  }
  </code></pre>
  <p>When the document loads I call <code>plan_state('me')</code>, and when certain things happen I may call <code>plan_state('loved')</code>. The problem occurs when I run a function and want to check the current state:</p>
  <pre><code>alert(plan_state());
  </code></pre>
  <p>I get <code>undefined</code> back, but the value should be 'me' as I previously set this value on document load.</p>
  <p>What am I doing wrong?</p>