This repository was archived by the owner on Sep 17, 2025. It is now read-only.
forked from ZycoNo007/Lab9_Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
230 lines (196 loc) · 5.94 KB
/
index.html
File metadata and controls
230 lines (196 loc) · 5.94 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab 9</title>
<style>
button {
margin: 3px;
}
button:hover {
cursor: pointer;
}
#first-num,
#second-num {
width: 60px;
}
output {
border: 1px solid gray;
display: block;
height: 18px;
margin-top: 5px;
padding: 5px;
width: 240px;
}
main {
width: 800px;
}
#error-btns {
column-gap: 5px;
display: flex;
flex-wrap: wrap;
margin-top: 30px;
row-gap: 5px;
}
#error-btns>* {
padding: 8px 2px;
width: 122px;
}
</style>
</head>
<body>
<main>
<form>
<fieldset>
<legend>Error Calculator</legend>
<input name="first-num" id="first-num" />
<select name="operator" id="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input name="second-num" id="second-num" />
<button id="calculate">Calculate</button>
<br />
<output></output>
</fieldset>
</form>
<section id="error-btns">
<button>Console Log</button>
<button>Console Error</button>
<button>Console Count</button>
<button>Console Warn</button>
<button>Console Assert</button>
<button>Console Clear</button>
<button>Console Dir</button>
<button>Console dirxml</button>
<button>Console Group Start</button>
<button>Console Group End</button>
<button>Console Table</button>
<button>Start Timer</button>
<button>End Timer</button>
<button>Console Trace</button>
<button>Trigger a Global Error</button>
</section>
</main>
<script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script>
<script>
window.TrackJS && TrackJS.install({
token: "c047cc5d155e48aa93ab5afac48d6f2d"
// for more configuration options, see https://docs.trackjs.com
});
</script>
<script>
let form = document.querySelector('form');
form.addEventListener('submit', e => {
e.preventDefault();
let output = document.querySelector('output');
let firstNum = document.querySelector('#first-num').value;
let secondNum = document.querySelector('#second-num').value;
let operator = document.querySelector('#operator').value;
output.innerHTML = eval(`${firstNum} ${operator} ${secondNum}`);
});
let errorBtns = Array.from(document.querySelectorAll('#error-btns > button'));
// Start your code here
// You may move this JS to another file if you wish
// console.log(errorBtns);
TrackJS.track('Testing TrackJS!');
// Console Log button
errorBtns[0].addEventListener('click', () => {
console.log('console log');
});
// Console Error button
errorBtns[1].addEventListener('click', () => {
console.error('you have an error in your program');
});
// Console count button
errorBtns[2].addEventListener('click', () => {
console.count('woah kenny error');
});
// Console warn button
errorBtns[3].addEventListener('click', () => {
console.warn('Your software is out of date!');
});
// Console assert button
errorBtns[4].addEventListener('click', () => {
const x = 33;
const y = 3;
const r = 'x should be greater than y'
console.assert(x < y, {x, y, r});
// console.assert(y < x, {x, y, r});
});
// Console clear button
errorBtns[5].addEventListener('click', () => {
console.clear();
});
// Console dir button
errorBtns[6].addEventListener('click', () => {
console.dir(document.head);
});
// Console dirxml button
errorBtns[7].addEventListener('click', () => {
console.dirxml(document);
});
// Console group start button
errorBtns[8].addEventListener('click', () => {
console.group('Bunch of Errors');
console.log('These are the errors within the group, "Bunch of Errors"');
});
// Console group end button
errorBtns[9].addEventListener('click', () => {
console.groupEnd();
console.log('The group for "Bunch of Errors" is closing');
});
// Console table button
errorBtns[10].addEventListener('click', () => {
console.table([ {first: 'Seeraj', last: 'Somla'}, {first: 'Dan', last: 'Parfait'}, {first: 'Oliver', last:'Tree'}]);
});
// Start timer button
errorBtns[11].addEventListener('click', () => {
console.time('Timer');
});
// End timer button
errorBtns[12].addEventListener('click', () => {
console.timeEnd('Timer');
});
// Console trace button
errorBtns[13].addEventListener('click', () => {
const fourth = () => { third(); };
const third = () => { second(); };
const second = () => { first(); };
const first = () => { console.trace(); };
fourth();
});
// Custom global error
class newGlobalError extends Error {
constructor(error) {
super(error);
this.name = "newGlobalError";
}
}
// Trigger a global event button
errorBtns[14].addEventListener('click', () => {
try {
throw error;
} catch(err) {
console.log('This error broke the program! Fix it.');
} finally {
alert('Throwing a Global Error!');
throw new newGlobalError('Global Error is being thrown');
}
});
// Function to call in window event listener when global error is triggered
function callGlobalError(message) {
alert(message);
}
// Event listener
window.addEventListener('error', () => {
console.log("Listening for Global Error...");
callGlobalError("You have caused a Global Error. Press 'OK' to continue.");
})
</script>
</body>
</html>