-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathindex.html
More file actions
228 lines (207 loc) · 6.07 KB
/
index.html
File metadata and controls
228 lines (207 loc) · 6.07 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
<!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: "8400504f285d4dd982780cafaa7b542e"
// 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
errorBtns[0].addEventListener("click", function() {
console.log("Console Log Demo");
});
errorBtns[1].addEventListener("click", function() {
console.error("Error here: error prompt");
});
errorBtns[2].addEventListener("click", function() {
console.count("Count button: ");
});
errorBtns[3].addEventListener("click", function() {
console.warn("Console warm button");
});
errorBtns[4].addEventListener("click", function() {
let number = 2;
console.log('the # is ' + number);
const errorMsg = 'The number doesn\'t equal to 3';
console.assert(number == 3, {number: number, errorMsg: errorMsg});
console.assert("number:2, errorMessage: ");
});
errorBtns[5].addEventListener("click", function() {
console.clear();
});
errorBtns[6].addEventListener("click", function() {
console.dir(errorBtns[6]);
});
errorBtns[7].addEventListener("click", function() {
console.dirxml(errorBtns[7]);
});
errorBtns[8].addEventListener("click", function() {
console.group();
});
errorBtns[9].addEventListener("click", function() {
console.groupEnd();
});
errorBtns[10].addEventListener("click", function() {
console.table([
{
first: 'Ray',
last: 'Brooklyn',
PID: 'A1234567890',
},
{
first: 'Annie',
last: 'Scarlet',
PID: 'A4567891023',
},
{
first: 'Cole',
last: 'Mailhot',
PID: 'A432567890',
}
]);
});
errorBtns[11].addEventListener("click", function() {
console.time();
});
errorBtns[12].addEventListener("click", function() {
console.timeEnd();
});
errorBtns[13].addEventListener("click", function() {
const handleBtnClick = () => { deep(); };
const deep = () => { deeper(); };
const deeper = () => { deepest(); };
const deepest = () => { console.trace(); };
handleBtnClick();
});
//Step 3: try/catch
let calculateButton = document.querySelector("#calculate");
calculateButton.addEventListener("click", function() {
let firstNum = document.querySelector('#first-num').value;
let secondNum = document.querySelector('#second-num').value;
let output = document.querySelector('output');
try{
console.log(firstNum);
console.log(typeof(firstNum));
if(isNaN(firstNum)){
throw new Error("Number entry error: the first number has to be a number.")
}
}catch(Error){
alert("Try another number for the first entry.");
}finally{
alert("Result is generated.");
}
//Step 4: Extending error
class ValidationError extends Error {
constructor(message) {
super(message);
this.name = "Second entry";
}
}
function test() {
if(isNaN(secondNum)){
throw new ValidationError("Number entry error: the second number has to be a number.")
}
}
try {
test();
}catch(err) {
alert(err.message);
alert("Reenter: " + err.name);
}
});
//Step 5: Trigger a Global Error
errorBtns[14].addEventListener("click", function() {
TrackJS.track('Testing TrackJS!');
});
</script>
</body>
</html>