-
Notifications
You must be signed in to change notification settings - Fork 0
/
bomb_challenge.html
155 lines (140 loc) · 4.78 KB
/
bomb_challenge.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bomb Challenge</title>
</head>
<body>
<section>
<textarea name="songs" id="songs" cols="30" rows="10"></textarea>
<button onclick="jackBox.play()">Start Jack Box</button>
<button onclick="jackBox.windUp()">Stop Jack Box</button>
</section>
<script>
// ================================= BOM CHALLENGES
//
// CHALLENGE 1: Build a Jack-In-The-Box
//
// Define an object called jackBox.
//
// Include properties for...
// triggered - whether or not the box has been sprung (should be false by default)
// intervalId - set to null
// play() - once called, if triggered is false, console.log one new element in the lyrics array every second
// after the lyrics, stop the interval, set the triggered property to true, and alert POP!
// windUp() - once called will stop the play() method and set triggered to false
// lyrics - an array with the following elements:
//
var jackBox =
{
triggered: false,
lyrics: ["All a-...",
"-round the ...",
"mulberry...",
"bush, The...",
"monkey...",
"chased the...",
"wea-...",
"-sel...",
"The monkey...",
"stopped to...",
"pull up his...",
"sock,...",
"Pop!...",
"goes the...",
"wea-...",
"-sel."],
intervalId: null,
// playlist: function () {
// // alert(this);
// for (var index = 0; index < this.lyrics.length; index++) {
// console.log(this.lyrics[index]);
// }
// },
play: function () {
// add reference to jackBox object
var that = this;
if (!this.triggered) {
// alert('1' + this);(;
// this.intervalId = setInterval(this.playlist,1000);
this.intervalId = setInterval(function () {
// console.log(that);
var str = "";
for (var index = 0;
index < that.lyrics.length;
index++
) {
console.log(that.lyrics[index]);
str += "<br>" + that.lyrics[index];
document.getElementById("songs").innerText = str;
};
//that.windUp();
},
1000
)
; //
// play() - once called, if triggered is false, console.log one
this.triggered = true;
alert('POP!');
}
},
windUp: function () {
alert ('Done');
clearInterval(this.intervalId);
this.triggered = false;
}
}
jackBox.play();
// jackBox.windUp();
// play() - once called, if triggered is false, console.log one new element in the lyrics array every second
// after the lyrics, stop the interval, set the triggered property to true, and alert POP!
// windUp() - once called will stop the play() method and set triggered to false
// lyrics - an array with the following elements:
//}
// "All a-...",
// "-round the ...",
// "mulberry...",
// "bush, The...",
// "monkey...",
// "chased the...",
// "wea-...",
// "-sel...",
// "The monkey...",
// "stopped to...",
// "pull up his...",
// "sock,...",
// "Pop!...",
// "goes the...",
// "wea-...",
// "-sel."
//
// Include methods for...
//
//
// CHALLENGE 2: Build a Stop Watch
//
// Define an object called stopWatch.
//
// Include the following properties...
//
// intervalId
// count
//
// Include the following methods...
//
// start() - starts console logging an increasing count every second
// pause() - pauses counter
// reset() - stops counter and resets count to zero
soptWatch ={
intervalId: null,
count: 0,
start: function(){
},
pause: function(){
},
reset: function(){
}
}
</script>
</body>
</html>