/
index.js
84 lines (65 loc) · 1.26 KB
/
index.js
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
// Import stylesheets
import './style.css';
// drill 1
function one() {
console.log('one');
}
function two(callback) {
console.log('two');
callback();
}
function three() {
console.log('three');
two(one);
}
three();
// drill 2
function process(fn, a, b) {
return fn(a, b);
}
function add(a, b) {
return a + b;
}
function subtract(a, b) {
return a - b;
}
const drill2 = document.getElementById('drill2');
drill2.innerHTML = `
<h2>Process Function</h2>
<div>Add: ${process(add, 6, 4) == 10 ? 'Passed':'Failed'}</div>
<div>Subtract: ${process(subtract, 6, 4) == 2 ? 'Passed':'Failed'}</div>
`;
// drill ? (May drop this)
function start() {
console.log('Starting countdown');
}
function tick(n) {
console.log(n);
}
function done() {
console.log('BOOM!');
}
function countdown(start, tick, done) {
start();
(function loop(i) {
setTimeout(function() {
tick(i--);
if(i > 0){
loop(i);
} else {
done();
}
}, 500);
})(10);
}
countdown(start, tick, done);
function startDownload() {
console.log('Download starting');
}
function downloadTick(n) {
console.log(`${(n/10)*100}% left`);
}
function downloadDone() {
console.log('Download complete');
}
countdown(startDownload, downloadTick, downloadDone);