title: javascript uncaught reference error onclick
body: <p>Trying to call a javascript function with a button, and the button is not doing anything on click. The debugger returns "uncaught reference error: printNumber is not defined.</p>
  
  <p><code>printNumber</code> is the function I want to call.</p>
  
  <p>I did a search and most people with this problem did not use the proper syntax for declaring their function, defined their function within another function (function out of scope), or put their functions after they are called. It turns out nothing in my head is running. I tried to put a prompt in it for example, and the prompt did not show up.</p>
  
  <p>Here is my script:</p>
  
  <pre><code>    &lt;head&gt;
      &lt;script type="javascript"&gt;
      var x=0;
      function addNumber(x){
          x = x + 1;
          return x;   
      }
  
      function printNumber(number){
          document.getElementById("number").innerHTML=addNumber(number);
      }
  
      &lt;/script&gt;
      &lt;/head&gt;
  </code></pre>
  
  <p>Here is my HTML:</p>
  
  <pre><code>    &lt;body&gt;
  &lt;p&gt;&lt;center&gt;&lt;b&gt;The number of times the button has been clicked is ... &lt;b&gt;&lt;p&gt;
  &lt;br&gt;
  &lt;div id="number"&gt;&lt;/div&gt;
  &lt;br&gt;
  &lt;form&gt;
      &lt;input type="button" id="StartButton" value="Click to add 1 to counter" onClick="printNumber(x)"&gt;
  &lt;/form&gt;
  &lt;/center&gt;
  </code></pre>
  
  <p></p>
  
  <p>Can anybody point out to me where the problem is coming from? Thank you, this is for a programming class, and I hope that others who might also encounter this will see this.</p>