Logic for looping
<p>I am using javascript function, where the loop should run 10 times, during these 10 times, it should throw a random question based on <em>,+ and - operations, in that too there should be 4 "+" questions, 3 "-" questions and 3 "</em>" questions. And the loop should not run more than 10 times, someone please frame a logic for this...</p>

<p>My code so far:</p>

<pre><code>&lt;script type="text/javascript"&gt;
        var op=new Array();
        var addCount=0;
        var subCount=0;
        var mulCount=0;
        var counter=0;
        var no;
        op[0]="+";
        op[1]="-";
        op[2]="x";

        Array.prototype.chooseRandom = function() 
        {
            return this[Math.floor(Math.random() * this.length)];
        };
        var a = [1, 2];
        var b = [0, 2];
        var c = [0, 1];

            no=Math.floor((Math.random()*3));
            while(addCount &lt; 4|| subCount &lt; 3 || mulCount &lt; 3)
            {

                    no=Math.floor((Math.random()*3));
                    if(no==0)
                    {
                        if(addCount&lt;4)
                        {
                            addCount++;
            var op1=Math.floor(Math.random() * (99 - 10+1)) + 10;
                var op2=Math.floor(Math.random() * (99 - 10+1)) + 10;
                        }
                        else
                        {
                            no=a.chooseRandom();
                        }
                    }       
                    else if(no==1)
                    {
                        if(subCount&lt;3)
                        {
                            subCount++;
            var no1=Math.floor(Math.random() * (99 - 10+1)) + 10;
            var no2=Math.floor(Math.random() * (99 - 10+1)) + 10;
                            if(no1&gt;no2)
                            {
                                 var op1=no1;
                                 var op2=no2;
                            }
                            else
                            {
                                var op1=no2;
                                var op2=no1;
                            }
                        }
                        else
                        {
                            no=b.chooseRandom();
                        }
                    }
                    else if(no==2)
                    {
                        if(mulCount&lt;3)
                        {
                            mulCount++;
            var op1=Math.floor(Math.random() * (99 - 10+1)) + 10;
            var op2=Math.floor(Math.random() * (9 - 1+1)) + 1;
                        }
                        else
                        {
                            no=c.choseRandom();
                        }
                    }

                    counter++;
            }
    &lt;/script&gt;
</code></pre>
