javascript - Logic for looping -
i using javascript function, loop should run 10 times, during these 10 times, should throw random question based on ,+ , - operations, in there should 4 "+" questions, 3 "-" questions , 3 "" questions. , loop should not run more 10 times, please frame logic this...
my code far:
<script type="text/javascript"> 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() { homecoming this[math.floor(math.random() * this.length)]; }; var = [1, 2]; var b = [0, 2]; var c = [0, 1]; no=math.floor((math.random()*3)); while(addcount < 4|| subcount < 3 || mulcount < 3) { no=math.floor((math.random()*3)); if(no==0) { if(addcount<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<3) { subcount++; var no1=math.floor(math.random() * (99 - 10+1)) + 10; var no2=math.floor(math.random() * (99 - 10+1)) + 10; if(no1>no2) { var op1=no1; var op2=no2; } else { var op1=no2; var op2=no1; } } else { no=b.chooserandom(); } } else if(no==2) { if(mulcount<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++; } </script>
make array containing required number of +
, -
, *
random sort aray using function below:
arr.sort(function() {return 0.5 - math.random()})
javascript
No comments:
Post a Comment