Checkbox Game

basic game with checkboxes

by bluey

HTML

<input type='checkbox' id='1' class='x' />
<input type='checkbox' id='2' class='x' />

<input type='checkbox' id='3' class='x' />
<input type='checkbox' id='4' class='x' />

<input type='checkbox' id='5' class='x' />
<input type='checkbox' id='6' class='x' />

<p>
    <span>Tries: <span id='tries_counter'>0</span></span><br />
     <span>Wins: <span id='wins_counter'>0</span></span>
</p>

JavaScript

function derp(winningComb , winningNumA, winningNumB) {
    var winningComb = winningNumA+','+winningNumB;
    var winningNumA = 3;
    var winningNumB = 6;
}
                    
derp();
                    
$('.x').change(function(winningComb , winningNumA, winningNumB){
 
  
    /** // fibonacci sequence
    var i;
    var fib = []; //Initialize array!
    
    fib[0] = 0;
    fib[1] = 1;
    for(i=2; i<=10; i++)
    {
        // Next fibonacci number = previous + one before previous
        // Translated to JavaScript:
        fib[i] = fib[i-2] + fib[i-1];
        //alert(fib[i]);
    }
    
    */
 
    /* should be rewriting winningComb but isnt on win*/
    
    
    var n = $("input:checkbox:checked").length; 
    if (n === 2) {
      var searchIDs = $('input:checkbox:checked').map(function(){
          return $(this).attr('id');
       });
       var selectedCombination = searchIDs.get();
        
        if (winningComb == selectedCombination) {
           // alert('you have won!');
           var wins = parseInt($('#wins_counter').text());
         $('#wins_counter').text(wins+1);
         $('input:checkbox:checked').removeAttr('checked');
            
            /* gen new numbers for pairing */
            
        var newNumA = Math.floor(Math.random() * 6) + 1; 
        var newNumB = Math.floor(Math.random() * 6) + 1; 
         if (newNumA == newNumB) {
             while(newNumA == newNumB){
                newNumB = Math.floor(Math.random() * 6) + 1; 
             }
          }
            alert(newNumA+'&'+newNumB);
             winningNumA = 3;
             winningNumB = 5;

           
        }
        else {
            $('input:checkbox:checked').removeAttr('checked');
            
        }
        //alert(selectedCombination);
        // alert(searchIDs.get());
         tries = parseInt($('#tries_counter').text());
         $('#tries_counter').text(tries+1);
    }
    
// alert($(this).attr('id'));
});