-
Notifications
You must be signed in to change notification settings - Fork 0
/
defuse-the-bom.html
52 lines (42 loc) · 1.32 KB
/
defuse-the-bom.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Defuse the BOM</title>
</head>
<body>
<h2 id="message">This BOM will self destruct in <span id="timer">5</span> seconds...</h2>
<button id="defuser">Defuse the BOM</button>
<script>
(function() {
"use strict";
var detonationTimer = 5;
// TODO: This function needs to be called once every second
var timerDetonate = setInterval(function updateTimer() {
if (detonationTimer === 0) {
clearInterval(timerDetonate);
alert('EXTERMINATE!');
document.body.innerHTML = '';
} else if (detonationTimer > 0) {
document.getElementById('timer').innerHTML = detonationTimer;
}
detonationTimer--;
}, 1000);
// TODO: When this function runs, it needs to
// cancel the interval/timeout for updateTimer()
function defuseTheBOM() {
clearInterval(timerDetonate);
alert("You stopped the bomb!");
}
//testing
// Don't modify anything below this line!
//
// This causes the defuseTheBOM() function to be called
// when the "defuser" button is clicked.
// We will learn about events in the DOM lessons
var defuser = document.getElementById('defuser');
defuser.addEventListener('click', defuseTheBOM);
})();
</script>
</body>
</html>