-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathohm.html
193 lines (176 loc) · 8.83 KB
/
ohm.html
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
<html>
<head>
<title>Ohm's Law practice (Series Circuits)</title>
<script src="common_utils.js"></script>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
body {
padding: 50px;
background: url('polyBkgYellow.svg');
background-size: cover;
}
table {
padding: 20px;
background: #fff;
border-radius: 5px;
}
h1 {
margin: 0px 40px 0px 40px;
color: #ddd;
font-size: 1.8em;
text-align: center;
}
</style>
<script>
var currentProblem = {
problem: '',
answerNumber: 0,
answerUnit: ''
}
var questionTextStrings = [
'(n) measures a circuit. The current is (i) and the resistance of the light bulb is (r).<br><br>What is the battery\'s output?', // Find V
'(n) powers their circuit with a battery that outputs (v). Then, (n) measured the current in the circuit to be (i).<br><br>What is the resistance of the light bulb?', // Find R
'(n) builds a circuit using a light bulb that has a resistance of (r) and a battery with an output of (v).<br><br>How much current is flowing through the circuit?' // Find I
]
var questionTextUnits = [
['V (Volts)'],
['\u03A9 (Ohms)'],
['A (Amps)']
]
var circuitDiagramSVG = ''; // Grab from innerHTML at page load.
function checkAnswer() {
var a = parseFloat($('#guessNumber').value);
var u = $('#guessUnit').value.replace(/Ω/g, '\u03A9');
var z = getScore();
if (Math.abs(a - currentProblem.answerNumber) <= 0.1 && u == currentProblem.answerUnit) {
z++;
setScore(z, 'Ohm\'s Law (Series)');
currentProblem = mathProblem();
$('#question').innerHTML = currentProblem.problem;
$('#tryagain').innerHTML = 'Correct!';
$('#guessNumber').value = '';
} else {
$('#tryagain').innerHTML = 'Incorrect, try again.';
}
if (u !== currentProblem.answerUnit) {
$('#guessUnit').value = ' ';
}
}
function skipAnswer() {
$('#guessNumber').value = '';
currentProblem = mathProblem();
$('#question').innerHTML = currentProblem.problem;
$('#tryagain').innerHTML = ' ';
$('#guessUnit').value = ' ';
}
function mathProblem() {
var m = randomName();
var n = Math.floor(Math.random() * 3);
var o = 0;
var s = questionTextStrings[n];
var p = [];
p[2] = Math.floor(Math.random() * 9 + 2) / 10;
p[1] = Math.floor(Math.random() * 15 + 2);
p[0] = p[2] * p[1];
var pStr = s.replace(/\(n\)/g, m)
.replace(/\(r\)/g, p[1].toFixed(0) + ' ' + questionTextUnits[1][o])
.replace(/\(i\)/g, p[2].toFixed(1) + ' ' + questionTextUnits[2][o])
.replace(/\(v\)/g, p[0].toFixed(1) + ' ' + questionTextUnits[0][o]);
var htmlString = circuitDiagramSVG;
if (n !== 0) {
htmlString = htmlString.replace(/Voltage/g, p[0].toFixed(1) + ' ' + questionTextUnits[0][o].split(' ')[
0]);
}
if (n !== 1) {
htmlString = htmlString.replace(/Resistance/g, p[1].toFixed(0) + ' ' + questionTextUnits[1][o].split(
' ')[0]);
}
if (n !== 2) {
htmlString = htmlString.replace(/Current/g, p[2].toFixed(1) + ' ' + questionTextUnits[2][o].split(' ')[
0]);
}
htmlString = htmlString.replace(/Voltage/g, '???').replace(/Resistance/g, '???').replace(/Current/g, '???');
return {
problem: htmlString + '<br><br>' + pStr,
answerNumber: p[n],
answerUnit: questionTextUnits[n][o]
}
}
</script>
</head>
<body>
<table border="0">
<tr>
<td>
<h3>Ohm's Law Practice Problems (Series Circuits)</h3>
<p>Helpful formulas:</p>
<p><em>
Volatge = Current × Resistance<br>
Current = Voltage ÷ Resistance<br>
Resistance = Voltage ÷ Current</em></p>
<hr/>
<h2>
Score: <span id="score">0
</span> - <span id="codeZ">
</span></h2>
<br/>
<div id="question">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 210 107" height="180px">
<g transform="translate(7 -101)">
<path fill="none" stroke="#000" stroke-width="1.3"
d="M40.4 179.4V203h61.4v-46.8l26-.2M40.2 136V115h84V156" />
<rect width="9.2" height="23.2" x="35.4" y="124.4" fill="#d4dcdc" stroke="#000"
stroke-linecap="round" stroke-linejoin="round" stroke-width=".8" ry="1.8" />
<rect width="19.2" height="69.2" x="30.4" y="127.4" fill="#d4dcdc" stroke="#000"
stroke-linecap="round" stroke-linejoin="round" stroke-width=".8" ry="3.4" />
<rect width="19.6" height="40.1" x="30.2" y="143.1" ry="0" />
<rect width="19.6" height="20.8" x="30.2" y="175.8" ry="4.1" />
<path fill="#d4dcdc" d="M35 187.9h10v2H35z" />
<path d="M35 134.6h10v2H35z" />
<path d="M41 130.6v10h-2v-10z" />
<path fill="#f5ef00" fill-opacity=".2" fill-rule="evenodd" stroke="#000" stroke-width=".8"
d="M118 151.7l15-.2c6.7-14.6 36.4-15.5 36.7 4.3.2 19.8-29.3 19.7-36.8 5.8l-15.1.3" />
<path fill="none" stroke="#000" stroke-width=".3"
d="M132.8 154.4s22.5-7.7 19.6 0c-3.7 10-3.4-5.3 0 3.6 3.5 9.5-19.7 1.2-19.7 1.2" />
<rect width="3.1" height="5" x="112.8" y="153.8" stroke="#000" stroke-linecap="round"
stroke-linejoin="round" stroke-width=".8" ry="1.1" />
<path fill="#d97b00" stroke="#000" stroke-linecap="round" stroke-linejoin="round"
stroke-width=".8" d="M114.5 150.5h18.9v12.2h-18.9z" />
<path fill="#f7f7f7" stroke="#000" stroke-linecap="round" stroke-linejoin="round"
stroke-width=".8"
d="M69 115.3a14.1 13.6 0 0114.1-13.5 14.1 13.6 0 0114.2 13.5 14.1 13.6 0 01-14 13.6A14.1 13.6 0 0169 115.4" />
<path fill="#fd0707" fill-rule="evenodd" stroke="#fd0505" stroke-width=".2"
d="M82.6 122.6l-3-16.2 5.3 15.1c-.2 1.8-.6 3-2.3 1.1z" />
<text x="70.9" y="139.3" font-size="10">Current</text>
<path fill="none" stroke="#000" stroke-width=".3"
d="M71.5 110.7l2.5 4v0M94.1 110.6l-2.3 3.8M75.8 107l1.1 3.7M89 106.9l-1.1 3.3M82.9 105.2v3.1" />
<text x="136.1" y="133.2" font-size="10">Resistance</text>
<text x="-8" y="164.4" font-size="10">Voltage</text>
</g>
</svg>
</div><br>
<div id="tryagain" style="font-size:12px;color:#aa0000;"> </div>
<input type="text" id="guessNumber" onFocus="$('#tryagain').innerHTML=' ';" />
<select id="guessUnit">
<option>--choose a unit--</option>
<option value="V (Volts)">V</option>
<option value="Ω (Ohms)">Ω</option>
<option value="A (Amps)">A</option>
</select>
<button id="check" onclick="checkAnswer()">check answer</button>
<button id="skip" onclick="skipAnswer()">skip</button><br><br><br>
<script>
circuitDiagramSVG = $('#question').innerHTML;
setScoreFromCookie('Ohm\'s Law (Series)', (checkScoreCookie) => {});
currentProblem = mathProblem();
$('#question').innerHTML = currentProblem.problem;
</script>
</td>
</tr>
</table>
</body>
</html>