-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbackVersion.js
More file actions
70 lines (63 loc) · 1.51 KB
/
Copy pathcallbackVersion.js
File metadata and controls
70 lines (63 loc) · 1.51 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
function getTired() {
return Math.random() < 0.3;
}
function mowYard(name, callback) {
setTimeout(() => {
console.log(`${name} mowed the yard.`);
callback();
}, 2000);
}
function weedEat(name, callback) {
setTimeout(() => {
if (getTired()) {
console.log(`${name} fell asleep after mowing the yard.`);
} else {
console.log(`${name} finished using the weed eater.`);
callback();
}
}, 1500);
}
function trimHedges(name, callback) {
setTimeout(() => {
if (getTired()) {
console.log(`${name} fell asleep after weed eating the yard.`);
} else {
console.log(`${name} finished trimming the hedges.`);
callback();
}
}, 1000);
}
function collectWood(name, callback) {
setTimeout(() => {
if (getTired()) {
console.log(`${name} fell asleep after trimming the hedges.`);
} else {
console.log(`${name} finished collecting wood.`);
callback();
}
}, 2500);
}
function waterGarden(name, callback) {
setTimeout(() => {
if (getTired()) {
console.log(`${name} fell asleep after collecting wood.`);
} else {
console.log(`${name} finished watering the garden.`);
callback();
}
}, 500);
}
function doSummerChores(name) {
mowYard(name, () => {
weedEat(name, () => {
trimHedges(name, () => {
collectWood(name, () => {
waterGarden(name, () => {
console.log(`${name} finished all their chores!`);
});
});
});
});
});
}
doSummerChores("Bob")