forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.html
45 lines (37 loc) · 722 Bytes
/
timer.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
<html>
<head>
<title>Webville Lounge</title>
<script>
var dj = {
playsound: function() {
console.log("Playing ", this.sound);
},
sound: "bells"
};
var controller = {
timer: null,
start: function() {
this.timer = setInterval(dj.playsound.bind(dj), 1000);
},
stop: function() {
clearInterval(this.timer);
}
};
window.onload = function() {
//controller.start();
var startButton = document.getElementById("start");
startButton.onclick = function() {
controller.start();
};
var stopButton = document.getElementById("stop");
stopButton.onclick = function() {
controller.stop();
};
};
</script>
</head>
<body>
<button id="start">start</button>
<button id="stop">stop</button>
</body>
</html>