0% found this document useful (0 votes)
11 views2 pages

!DOCTYPE HTML PUBLIC - W3CDTD XHTML

Uploaded by

hindsea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

!DOCTYPE HTML PUBLIC - W3CDTD XHTML

Uploaded by

hindsea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

3 <html>

4
11 <head>
12 <title>Math Practice</title>
13 <style type="text/css">
14 h1 {
15 text-align: center;
16 font-family: Sans-Serif;
17 font-weight: bold;
18 font-size: 36px;
19 margin: 20px 0 30px 0;
20 padding: 0;
21 }
22 table {
23 width: 100%;
24 margin-left: auto;
25 margin-right: auto;
26 font-family: Sans-Serif;
27 font-size: 28px;
28 }
29 td {
30 height: 9.5em;
31 width: 15em;
32 vertical-align: top;
33 text-align: center;
34 }
35 </style>
36 <script>
37 function single_problem() {
38 // Set to true for equations, false for expressions.
39 var eqn = true;
40
41 // Construct the parts of the binomial (a1*x + c1)(a2*x + c2)
42 // Coefficients. Small numbers, usually 1.
43 var coeffs = [1, 1, 1, 2, 3, 4]
44 var a1 = coeffs[Math.floor(Math.random()*6)];
45 var a2 = coeffs[Math.floor(Math.random()*6)];
46
47 // Constants
48 var c1 = Math.floor(Math.random()*9 + 1);
49 var c2 = Math.floor(Math.random()*9 + 1);
50
51 // Change the signs of the constants at random.
52 if (Math.random() < .5) {
53 c1 = -c1;
54 }
55 if (Math.random() < .5) {
56 c2 = -c2;
57 }
58
59 // Put in standard form
60 var A = a1*a2;
61 var B = a1*c2 + a2*c1;
62 var C = c1*c2;
63 var opB = opC = '+';
64 var quad = 'x<sup>2</sup> '
65 var lin = 'x '
66
67 // Determine the operators.
68 if (C < 0) {
69 opC = '&#8722;';
70 C = -C;
71 }
72
73 if (B < 0) {
74 opB = '&#8722;';
75 B = -B;
76 }
77 else if (B == 0) {
78 opB = '';
79 B = '';
80 lin = '';
81 }
82
83 // Don't show coefficients that are 1.
84 if (A == 1) A = '';
85 if (B == 1) B = '';
86
87 term = A + quad + opB + ' ' + B + lin + opC + ' ' + C;
88
89 if (eqn) return term + ' = 0';
90 else return term;
91
92 }
93 </script>
94 </head>
95 <body>
96 <h1>Math Practice</h1>
97 <table id="whole">
98 <script>
99 for (i=0; i<3; i++){
100 document.write("<tr>");
101 for (j=0; j<2; j++) {
102 document.write('<td>' + single_problem() + '</td>');
103 }
104 document.write('</tr>');
105 }
106 </script>
107 </table>
108
109 </body>
110 </html>

You might also like