title: HTML / Javascript ReferenceError: Can't find variable
body: <p>I've made extensive use of the search function and whilst there seem to be many instances of this problem, none are close enough for me to glean a solution to my variant of the problem.</p>
  <p>I'm using vanilla Javascript to create a multiplication game. When the button is pressed either by the user pressing 'Enter' or clicking the button the console shows me this error:</p>
  <blockquote>
  <p>ReferenceError: Can't find variable: checkAnswer</p>
  </blockquote>
  <p>Here is the code:</p>
  <pre><code>var user_answer;
    for(var x in questions){
      document.getElementById(&quot;bronze&quot;).innerHTML = '&lt;p&gt;' + questions[x] + '&lt;/p&gt;';
      document.getElementById(&quot;bronze&quot;).innerHTML += '&lt;p&gt;&lt;input type=&quot;number&quot; id=&quot;user_input&quot;&gt;&lt;/p&gt;';
      document.getElementById(&quot;bronze&quot;).innerHTML += '&lt;p&gt;&lt;button type=&quot;button&quot; id=&quot;submit_button&quot; onclick=&quot;checkAnswer()&quot;&gt;Enter&lt;/button&gt;&lt;/p&gt;';
      var user_input = document.getElementById(&quot;user_input&quot;);
      user_input.addEventListener(&quot;keyup&quot;, function(event){
        if(event.keyCode == 13){
          event.preventDefault();
          document.getElementById(&quot;submit_button&quot;).click();
        }
      });
      function checkAnswer(){
        user_answer = document.getElementById(&quot;user_input&quot;).value;
        if(user_answer == answers[x]){
          alert('Correct!');
        } else {
          alert('Wrong!');
        }
      }
    }
  </code></pre>
  <p>Edit to say that questions and answers are arrays each containing the questions and corresponding answers in the same position. So questions will be like [1x2,2x2,...] and answers [2,4,...]</p>