title: Variables behaving badly - in javascript - in functions
body: <p>First off, here's my code:</p>
  
  <pre><code>var variable1 = 10;
    function f1 (){
    alert(variable1);
    }
  //When button is pressed, call function
  $("#button").click(f1);
  </code></pre>
  
  <p>Why can I not access variable1 inside the function?
  Many thanks and a Happy Christmas.</p>
  
  <h2>Modified question</h2>
  
  <pre><code>$(document).ready(function() {
  
  var how_many_words = 3;
  alert(how_many_words);  //This happens
  
  $("input").keypress(check_word);
  
  function check_word(){
  alert('hello');         //This happens
  alert(how_many_words);  //This doesn't
      }
  
      });
  </code></pre>