Javascript method crashes - I just dont understand why
<p>I m writing an application where you can play lottery, if you shake the phone, 6 random numbers will get filled out on your lottery ticket. The function which gets the random numbers and fills them out crashes.</p>

<p>this is my document.ready</p>

<pre><code>$(document).ready(function() {  
                    //initialising some variables, not related here
        //...

                    //Clickhandler for a number clicked
        $('#ticket_detail .tipfield .tipbox ul li').click(function() 
            {clickNumber(this); 
        });
                    //testmethod to test the crashing method
        testRandomNumbers();

    })
</code></pre>

<p>In the javascript file, there is the test Method</p>

<pre><code> function testRandomNumbers(){

    //invokes crashing numbers many times - causes crash
    for (var z = 0; z&lt;10;z++){

        randomNumbers();

    }



}
</code></pre>

<p>...which invokes the crashing method</p>

<pre><code>function randomNumbers(){ 

    //counter for 6 random numbers
counter = 0;

    //empties the lottery, method is listed below
clearAllNumbers();

    //array to save the numbers
randomNumberArray = [];



//6 runs for 6 random numbers
while (counter &lt; 6){ 

        //get the random number
        randomNumber = Math.floor((Math.random()*49)+1);



        //check the number with an array to make sure it is not there already - 6 numbers have to be unique
        for (var j = 0; j &lt; 6; j++){

            if (randomNumberArray[j]==randomNumber){

                isUniqueNumber = false;

                break;

            } 

        }

        randomNumberArray[counter]=randomNumber;  



        //if number is Unique, get the next number
        if (isUniqueNumber){ 

            counter++;

        } 

  } 


//after it, go through the array with the random numbers and put graphics on the numbers in the lottery ticket with jQuery
for (var q = 0;q&lt;randomNumberArray.length;q++){

    clickNumber($('#ticket_detail .tipfield .tipbox ul li').filter(function(){return $(this).html() == randomNumberArray[q];}));

}




}
</code></pre>

<p>the clearAllNumbres() method</p>

<pre><code>    function clearAllNumbers(){

    $('#ticket_detail .tipfield .tipbox ul li img').remove(); 

    $('#ticket_detail .tipfield .tipbox ul li').removeClass('selected');

    lottoNumbers = [];

}  
</code></pre>

<p>So this is all I do. 6 runs while loop times 6 runs for loop where I make few variable assignments and boolean operations. Why does the method crash? Any Ideas</p>

<p>edit: You may wonder where all the variables are initialized. There either initialised in the document.ready() or on top of the javascript file</p>

<p>edit: I know we all like stack traces. Sadly I dont get an error why it crashes. I counted how many times the randomNumbers() Method runs and it mostly crashes after the 2nd or 3rd run. The browser cant load the page and soon shows an error message (tested on chrome, opera and firefox, all latest versions)
Any help greatly appreciated.</p>
