title: Jquery Compare two variables to see if they match, but one is out of scope?
body: <p>For a small puzzle/memory game, I want to compare two pieces of the puzzle. If they are the same (have the same letter) i want to alert ('match'). I think I'm on the right way, but now one of the variables seems out of scope, because I don't know where in my code I should put it. So now it returns the second piece but the first stays undefined. Can you help me please? Much appreciate it!</p>
  
  <p>Click on shuffle &amp; show, after that click 2 pieces, you'll see the 'undefined' statement.
  I'd like to know WHY it doesn't work and what will make it work and why :P</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;button id="shuffle"&gt;Show and Shuffle&lt;/button&gt;
  
  &lt;div id="container"&gt;
     &lt;div class="choices"&gt;&lt;div class="letter"&gt;A&lt;/div&gt;&lt;/div&gt;
     &lt;div class="choices"&gt;&lt;div class="letter"&gt;B&lt;/div&gt;&lt;/div&gt;
     &lt;div class="choices"&gt;&lt;div class="letter"&gt;C&lt;/div&gt;&lt;/div&gt;
     &lt;div class="choices"&gt;&lt;div class="letter"&gt;A&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var amountofclicks = 0;
  var firstcard = false;
  var secondcard = false;
  
  $('#shuffle').bind('click', function() {
  
      var divs = $("div.choices").get().sort(function() {
          return Math.round(Math.random());
      }).slice(0, 16);
  
      $(divs).appendTo(divs[0].parentNode).show();
  
  });
  
  $('.choices').bind('click', function() {
  
      if (amountofclicks &lt; 2) {
          amountofclicks++;
          $(this).unbind('click');
          if (amountofclicks == 1) {
              firstcard = true;
              var txt = $(this).find('.letter').text();
  
          }
  
          if (amountofclicks == 2) {
              secondcard = true;
  
              var txt2 = $(this).find('.letter').text();
              alert(txt + ' ' + txt2);
  
  
          }
  
      }
  
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/QxSxh/" rel="nofollow"><strong>JSFIDLLE WITH PROBLEM</strong></a></p>