-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinalp.html
More file actions
276 lines (246 loc) · 8.43 KB
/
Copy pathfinalp.html
File metadata and controls
276 lines (246 loc) · 8.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<html>
<head>
<style>
table, td {text-align:center; border:1px solid black;}
.red {color:red;}
</style>
<script>
var rng;
function RNG(s)
{
this.m = 0X80000000;
this.a = 1103515245;
this.c = 12345;
this.seed = s ? s : Math.floor(Math.random() * (this.m-1));
}
RNG.prototype.nextInt = function()
{
this.seed = (this.a * this.seed + this.c) % (this.m-1);
return this.seed;
}
RNG.prototype.nextFloat = function()
{
return this.nextInt() / (this.m - 1);
}
function Random()
{
return rng.nextFloat();
}
var showAnswers = false;
function newExam()
{
var num = Math.floor(Math.random()*10000+5000);
examID.value=num;
loadExam(false);
}
function loadExam(shouldAnswer)
{
showAnswers=shouldAnswer;
var x = examID.value;
x=parseInt(x);
if(isNaN(x))
{
alert("Value "+examID.value+" is NOT an integer");
newExam();
return;
}
x=x%15000;
rng = new RNG(x);
examID.value=x;
createExam();
}
function decToBinary(dec)
{
var bin = "";
var tmp = dec;
var p = 1;
while(tmp>0)
{
if(tmp%2==1)
{
bin="1"+bin;
}
else
{
bin="0"+bin;
}
p*=2;
tmp=Math.floor(tmp/2);
}
while(bin.length<8)
{
bin="0"+bin;
}
bin = bin.slice(0,4)+" "+bin.slice(4,8);
return bin;
}
function createExam()
{
lines = [];
var index=0;
var r = Math.floor(Random()*4);
var map= ["binary","octal","decimal","hexadecimal"];
var s="Describe the advantages of encoding a number as "+map[r]+". When is it typically used?<br>";
if(showAnswers)
{
s+="<p class='red'>";
}
else
{
s+="<p>";
}
if(r==0&&showAnswers){s+="Binary has only two values: on and off. Computers can understand electricity on/off. All computer memory really is binary.";}
if(r==1&&showAnswers){s+="Octal is no longer used as often. It is mostly found in security programs and aircraft transponder codes.";}
if(r==2&&showAnswers){s+="Decimal has ten values like our hands. Humans are taught to work with decimal early on and are most comfortable with decimal.";}
if(r==3&&showAnswers){s+="Hexadecimal needs new digits A to F, but it compresses large numbers into few digits and aligns perfectly with bytes.";}
lines[index++]=s+"</p>";
var dec = Math.floor(Random()*128+120);
var bin = decToBinary(dec);
var hMap =['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
var hex=hMap[Math.floor(dec/16)]+hMap[dec%16];
var oct=''+(Math.floor(dec/64))+(Math.floor(dec/8)%8)+(dec%8);
r = Math.floor(Random()*4);
s="<table><tr><th colspan='4'>Convert the number into the other bases</th></tr><tr><th>Base-10</th><th>Base-2</th><th>Base 8</th><th>Base 16</th></tr>";
if(showAnswers)
{
s+="<tr class='red'>";
}
else
{
s+="<tr>";
}
s+="<td>";
if(r==0||showAnswers){s+=dec;}
s+="</td><td>";
if(r==1||showAnswers){s+=bin;}
s+="</td><td>";
if(r==2||showAnswers){s+=oct;}
s+="</td><td>";
if(r==3||showAnswers){s+=hex;}
s+="</td></tr></table>";
lines[index++]=s+"<br>";
s="Create a truth table for ";
r=Math.floor(Random()*3);
if(r==0)
{
s+="!A ∧ (C ∨ B).<br>";
}
else if(r==1)
{
s+="(A ∨ !A) ∨ B.<br>";
}
else if(r==2)
{
s+="(!A ∧ B) ∨ !C.<br>";
}
if(showAnswers)
{
s+="<p class='red'>";
}
else
{
s+="<p>";
}
if(r==0&&showAnswers)
{
s+="Remember that the values for A, B, and C represent all the number 0 to 7<br>";
s+="<table class='red'>"
s+="<tr><th>#val</th><th>A</th><th>B</th><th>C</th><th>C∨B</th><th>A∧(C∨B)</th></tr>";
s+="<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>";
s+="<tr><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td></tr>";
s+="<tr><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td></tr>";
s+="<tr><td>3</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td></tr>";
s+="<tr><td>4</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>";
s+="<tr><td>5</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td></tr>";
s+="<tr><td>6</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>";
s+="<tr><td>7</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr>";
s+="</table>"
}
else if(r==1&&showAnswers)
{
s+="Remember that the values for A and B represent all the number 0 to 3<br>";
s+="<table class='red'>"
s+="<tr><th>#val</th><th>A</th><th>B</th><th>!A</th><th>A∨!A</th><th>(A∨!A)∨B</th></tr>";
s+="<tr><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td><td>1</td></tr>";
s+="<tr><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td></tr>";
s+="<tr><td>2</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td></tr>";
s+="<tr><td>3</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>";
s+="</table>"
}
else if(r==2&&showAnswers)
{
s+="Remember that the values for A, B, and C represent all the number 0 to 7<br>";
s+="<table class='red'>"
s+="<tr><th>#val</th><th>A</th><th>B</th><th>C</th><th>!A</th><th>!C</th><th>!A∧B</th><th>(!A∧B)∨!C</th></tr>";
s+="<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td></tr>";
s+="<tr><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr>";
s+="<tr><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td></tr>";
s+="<tr><td>3</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>";
s+="<tr><td>4</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>";
s+="<tr><td>5</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>";
s+="<tr><td>6</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>";
s+="<tr><td>7</td><td>1</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>";
s+="</table>"
}
lines[index++]=s+"</p>";
s="Define these two terms as they apply to computer architecture: ";
tmp = ["Input","Output","Processor","Memory"];
tmp2 = ["Input devices allow the user to tell the computer information","Output devices allow the computer to tell the user information","The processor does all the thinking in the computer: math and logic","Memory holds all data and the program itself"]
var answer = "";
for(let i=0;i<2;i++)
{
let x = Math.floor(Random()*tmp.length);
s+=tmp[x]+" ";
answer+=tmp2[x]+"<br>";
if(i==0){s+="and ";}
tmp.splice(x,1);
}
if(showAnswers)
{
s+="<p class='red'>"+answer;
}
else
{
s+="<p>";
}
s+="</p>"
lines[index++]=s+".<br>";
s="What is the purpose of a 'NIC' card?<br>";
answer = "The NIC (network interface card) allows the computer to connect to another over the internet."
if(Random()<.5)
{
s="What is the purpose of a 'Graphics' card?<br>";
answer="The graphics card allows the computer to put information on the screen, especially doing math that is specific to graphics.";
}
if(showAnswers)
{
s+="<p class='red'>"+answer;
}
else
{
s+="<p>";
}
s+="</p>"
lines[index++]=s;
var final="<ol>";
while(lines.length>0)
{
index=lines.length-1;
//index=Math.floor(Random()*lines.length);
tmp=lines[index];
lines.splice(index,1);
final+="<li>"+tmp+"</li>";
}
final+="</ol>";
output.innerHTML=final;
}
</script>
</head>
<body>
<button onclick="newExam()">Randomize</button><br>
<p><b>Exam ID: </b><input type="text" id="examID"></input>
<button onClick="loadExam(false)">Load</button>
<button onClick="loadExam(true)">Answer</button></p>
<p id="output"></p>
</body>
</html>