-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.js
51 lines (47 loc) · 1.27 KB
/
object.js
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
let game = {
startTime : null,
stopTime : null,
seconds : null,
displayArea : document.getElementById('display-area'),
start : function () {
game.displayArea.innerText = '計測中';
game.startTime = Date.now();
},
stop: function () {
document.body.removeEventListener(
'keydown',
game.stop
);
document.body.addEventListener(
'keydown',
game.retry
);
game.stopTime = Date.now();
game.seconds = (game.stopTime - game.startTime) / 1000;
if (9.5 <= game.seconds && game.seconds <= 10.5) {
game.displayArea.innerText = game.seconds + '秒でした。すごい!';
} else {
game.displayArea.innerText = game.seconds + '秒でした。残念。';
}
},
retry: function () {
if (confirm('リトライをしますか')){
game.start();
document.body.removeEventListener(
'keydown',
game.retry
);
document.body.addEventListener(
'keydown',
game.stop
);
}
}
};
if (confirm('OKを押して10秒だと思ったら何かキーを押して下さい')) {
game.start();
document.body.addEventListener(
'keydown',
game.stop
);
}