-
Notifications
You must be signed in to change notification settings - Fork 0
/
defuse-the-bom.html
50 lines (41 loc) · 1.25 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
<!DOCTYPE html>
<html lang="en">
<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";
let detonationTimer = 5;
let interval = 1000;
// TODO: This function needs to be called once every second
function updateTimer() {
if (detonationTimer === 0) {
alert('EXTERMINATE!');
document.body.innerHTML = '';
} else if (detonationTimer > 0) {
document.getElementById('timer').innerHTML = detonationTimer;
}
detonationTimer--;
}
let timer = setInterval(updateTimer, interval)
// TODO: When this function runs, it needs to
// cancel the interval/timeout for updateTimer()
function defuseTheBOM() {
clearTimeout(timer)
}
// 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
let defuser = document.getElementById('defuser');
defuser.addEventListener('click', defuseTheBOM);
})();
</script>
</body>
</html>