-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.html
More file actions
163 lines (134 loc) · 4.88 KB
/
timer.html
File metadata and controls
163 lines (134 loc) · 4.88 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Stopwatch practice</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap');
body,
input,
select,
textarea,
body * {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
body {
padding: 50px;
background: url('polyBkgRed.svg');
background-size: cover;
min-height: 100vh;
}
.infoText {
color: #ccc;
font-size: 0.8em;
}
#qField {
padding: 20px;
background: #fff;
border-radius: 5px;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.25em;
}
</style>
<script src="common_utils.js"></script>
</head>
<body>
<main id="qField">
<h1>Measurement Practice - Stopwatch</h1>
<hr>
<div id="result" class="car_image">
<svg viewBox="0 0 800 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="M0,40 800,40" stroke="#ddd" stroke-width="80" />
<path d="M100,0 100,80" stroke="#000" stroke-width="3" stroke-dasharray="5,5" />
<path id="finishLine" d="M0,0 0,80" stroke="#000" stroke-width="3" stroke-dasharray="5,5"
transform="translate(700,0)" />
<g id="car" transform="translate(0,0)">
<path id="car0" d="M25,15 40,15 40,65 25,65Z" fill="#222" />
<path id="car1" d="M80,15 95,15 95,65 80,65Z" fill="#222" />
<path id="car2" d="M20,20 100,20 100,60 20,60Z" fill="#777" />
<path id="car3" d="M20,20 100,20 100,60 20,60Z" fill="#aaa" />
</g>
</svg>
</div>
<table>
<tr>
<td style="max-width:300px;">
Use a stopwatch (on your phone is okay) to time how long it takes the car to cross the finish
line.<br>
<br>Use the "Go!" button to start the car.</td>
<td style="padding-left:40px;"><button id="carGo" onclick="startCar(theAccel, endPos);">Go!</button>
</td>
</tr>
</table><br>
Time: <input type="text" title="Your Answer" id="guessWidth" onFocus="$('#tryagain').innerHTML=' ';" size="5" />
seconds<br><br>
<div id="tryagain" style="font-size:12px;color:#aa0000;"> </div>
<button id="check" onclick="checkAnswer()">check answer</button>
<br><br>
<button id="setup" onclick="setFinish();">skip</button>
<hr>
<h2>Score: <span id="score">0
</span> - <span id="codeZ">
</span>
</h2>
</main>
<script>
var endPos = 700;
var theAccel = 0.08;
var theInterval = 10;
var theTime = -5;
setScoreFromCookie('Stopwatch', (checkScoreCookie) => {});
function setFinish() {
endPos = Math.floor(Math.random() * 250 + 500);
$('#finishLine').transform.baseVal.getItem(0).setTranslate(endPos, 0);
theAccel = Math.random() * 0.06 + 0.05;
theInterval = Math.random() * 30 + 10;
theTime = -5;
}
function startCar(ac, ep) {
var carPos = 0;
var accel = ac;
var accelAmt = ac;
var stamp = performance.now();
var mover = setInterval(function () {
if (carPos) {
$('#car').transform.baseVal.getItem(0).setTranslate(carPos, 0);
}
carPos += accelAmt;
accelAmt += accel;
if (carPos <= (ep - 92) && carPos > (ep - 192)) {
theTime = (performance.now() - stamp) / 1000;
}
if (carPos > 700) {
clearInterval(mover);
setTimeout(function () {
$('#car').transform.baseVal.getItem(0).setTranslate(0, 0);
}, 1000);
}
}, theInterval);
}
function checkAnswer() {
var aw = parseFloat($('#guessWidth').value);
var z = getScore();
var awDiff = Math.abs(aw - theTime);
if (awDiff < .26) {
z++;
setScore(z, 'Stopwatch');
setFinish();
$('#tryagain').innerHTML = 'Correct!';
$('#guessWidth').value = '';
} else {
$('#tryagain').innerHTML = 'Incorrect, try again.';
}
if (awDiff >= 1) {
$('#guessWidth').value = '';
}
}
setFinish();
</script>
</body>
</html>