function rnd(a,b) {
return a + Math.floor(Math.random()*(b-a+1));
}
function rndz(a,b) {
var x;
do {
x=rnd(a,b);
} while ( x==0);
return x;
}
function hcf(a,b) {
var c;
while ( b!=0 ) {
c = a%b; a=b; b=c;
}
return a;
}
function q1(){
var a = rnd(1,3);
var b = a + rnd(1,3);
var c = b + rnd(1,3);
var d = c + rnd(1,3);
var e = d + rnd(1,3);
ans = (a+b+c+d+e)/5;
qstr+="Find the mean of the numbers: " + a + ", " + b + ", " + c;
qstr+=", " + d + ", " + e + ".";
hint+="To calculate the mean, you need to add all the numbers together ";
hint+="and then divide by the number of numbers.";
}
function q2(){
var a = rnd(1,3);
var b = a + rnd(1,3);
var c = b + rnd(1,3);
var d = c + rnd(1,3);
var e = d + rnd(1,3);
var f = e + rnd(1,3);
ans = (a+b+c+d+e+f)/6;
ans=Math.round(ans*100)/100;
qstr+="Find the mean of the numbers: " + a + ", " + b + ", " + c;
qstr+=", " + d + ", " + e + ", " + f + ".";
qstr+="
Give your answer correct to 2 decimal places.";
hint+="To calculate the mean, you need to add all the numbers together ";
hint+="and then divide by the number of numbers.";
}
function q3(){
var a = rnd(1,3);
var b = a + rnd(1,3);
var c = b + rnd(1,3);
var d = c + rnd(1,3);
var e = d + rnd(1,3);
ans = c;
qstr+="Find the median of the numbers: " + a + ", " + b + ", " + c;
qstr+=", " + d + ", " + e + ".";
hint+="To calculate the median, you need to find the middle number when the numbers ";
hint+="are in increasing order.";
}
function q4(){
var a = rnd(1,3);
var b = a + rnd(1,3);
var c = b + rnd(1,3);
var d = c + rnd(1,3);
var e = d + rnd(1,3);
var f = e + rnd(1,3);
ans = (c+d)/2;
qstr+="Find the median of the numbers: " + a + ", " + b + ", " + c;
qstr+=", " + d + ", " + e + ", " + f + ".";
hint+="To calculate the median, you need to find the middle number when the numbers ";
hint+="are in increasing order. When there are an even number of numbers, you need to ";
hint+="find the average of the two middle numbers.";
}
function q5() {
var a = rnd(1,4);
var b = 6-a;
ans=b+"/6";
qstr+="If a single six-sided die is rolled once, what is the probability of getting ";
qstr+="
a score greater than " + a + "?";
qstr+="
Give your answer as a fraction.";
hint+="There are " + b + " ways a die can give a score greater than " + a + ".";
}
function q6(){
var a=rnd(2,12);
if (a<8) b=a-1;
else b=13-a;
ans=b+"/36";
qstr+="If two six-sided dice are rolled together, find the probability ";
qstr+="that the total score is " + a + ".";
qstr+="
Give your answer as a fraction.";
hint+="Draw a diagram (6x6) to represent the 36 possible outcomes,";
hint+="
then count those that give a total score of " + a + ".";
}
function q7(){
var a = rnd(8,12);
var b = rnd(10,20);
ans = a*b;
qstr+="If the mean of " + a + " test scores is " + b + ", what is the total ";
qstr+="of the " + a + " scores?";
hint+="Since MEAN = TOTAL / NUMBER, we have TOTAL = MEAN x NUMBER.";
}
function q8(){
var a = rnd(9,10);
var b = rnd(10,20);
var c = b + rnd(2,8);
ans = (a*b+c)/(a+1);
ans = Math.round(ans*100)/100;
qstr+="After taking " + a + " tests, my mean score is " + b;
qstr+="
In the next test my score is " + c + ". What is my new mean score?";
qstr+="
Give your answer correct to 2 decimal places.";
hint+="First work out my total score after " + a + " tests,";
hint+="
then add my next score, and finally divide by " + eval(a+1);
}
function q9(){
var a=new Array();
for (var i=1; i<=7; i++ ) a[i]=rnd(3,20);
var b=3;
var c=20;
for (i=1; i<=7; i++ ) {
if (a[i]>b) b=a[i];
if (a[i]
";
for (i=1; i<=7; i++ ) qstr+=a[i] + ", ";
qstr+="";
hint+="The range is the difference between the largest and smallest numbers in the sample.";
}
function q10(){
var a=rnd(1,3);
if (a==1) ans="7/8";
if (a==2) ans="4/8";
if (a==3) ans="1/8";
qstr+="If an unbiased coin is tossed 3 times, find the probability that "
if (a==3) qstr+=" exactly ";
else qstr+=" at least ";
qstr+= a;
if (a==1) qstr+=" head is obtained.";
else qstr+=" heads are obtained.";
hint+="There are 8 possible outcomes for this experiment:
";
hint+="HHH, HHT, HTH, THH, TTH, THT, HTT, TTT.";
}
function q11(){
var a = rnd(2,6);
var b = a-1;
ans=b+"/6";
qstr+="If a single six-sided die is rolled once, what is the probability of getting ";
qstr+="
a score less than " + a + "?";
qstr+="
Give your answer as a fraction.";
hint+="There are " + b + " ways a die can give a score less than " + a + ".";
}
function q12(){
var t, j;
var a = new Array();
a[1] = rnd(8,12);
a[2] = a[1];
a[3] = a[1];
a[4] = a[1] + rndz(-3,3);
a[5] = a[4];
a[6] = a[1] + rndz(-1,1)*rnd(4,7);
a[7] = a[1] + rndz(-1,1)*rnd(4,7);
ans = a[1];
for (var i=0; i<10; i++ ) {
j = rnd(2,7);
t = a[j]; a[j] = a[1]; a[1] = t;
}
qstr+="Find the mode of the numbers in the following sample:
";
for (i=1; i<=7; i++) qstr+= a[i] + ", ";
qstr+="";
hint+="The mode is the number which occurs most often in the sample.";
}
function q13() {
}
function q14() {
}
function q15(){
}
function q16(){
}
function q17() {
}
function q18() {
}
function question(n) {
do {
choice=rnd(1,12);
} while (choice==last1 || choice==last2 || choice==last3);
last3=last2;
last2=last1;
last1=choice;
qstr="";
hint="";
switch (choice) {
case 1: q1(); break;
case 2: q2(); break;
case 3: q3(); break;
case 4: q4(); break;
case 5: q5(); break;
case 6: q6(); break;
case 7: q7(); break;
case 8: q8(); break;
case 9: q9(); break;
case 10: q10(); break;
case 11: q11(); break;
case 12: q12(); break;
case 13: q13(); break;
case 14: q14(); break;
case 15: q15(); break;
case 16: q16(); break;
case 17: q17(); break;
case 18: q18(); break;
default: alert("cannot happen! choice = " + choice);
}
}