-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkSampleCallback.js
36 lines (31 loc) · 1.47 KB
/
workSampleCallback.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
'use strict';
// example function with different callbacks
let hasDeliveryArrived = true;
let isElectricity = true;
function doSimpleWork(simpleAction) {
if (hasDeliveryArrived) { console.log(`1. The task < ${simpleAction} > is completed.`);
return true
} else {console.log("1. Unfortunately, it has not been delivered yet.");
return false };
}
function doTesting() { // A function that will be passed as a callback.
if (isElectricity) { console.log('3a. In progress < Testing quality of the spare parts. >');
return true
} else { console.log("3. We cannot do this without electricity.");
return false};
};
function doPacking() { // A function that will be passed as a callback.
if (isElectricity) { console.log('3b. In progress < Packing the parts according to the orders. >');
return true
} else { console.log("3. We cannot do this without electricity.");
return false};
};
function doСomplexWork(firstTask, secondTask, callback) { // A function that will execute actions consecutively.
if (!doSimpleWork(firstTask)) return;
console.log(`2. Process < ${secondTask} > has been executed.`);
callback();
console.log("Сomplex work is done.");
};
doСomplexWork('Unload parts at the warehouse № 1.', 'Bring the parts to the engineering department.', doTesting);
hasDeliveryArrived = false;
doСomplexWork('Transfer quality parts to the warehouse № 2.', 'Bring the parts to the workshop.', doPacking);