-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
77 lines (62 loc) · 1.91 KB
/
main.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
function bakeCake() {
console.log("Starting the cake baking process...");
console.log("Preparing cake batter...");
console.log(`Measuring flour cups of 1`);
const sugar = measureIngredients("sugar", 1);
const eggs = measureIngredients("eggs", 3);
const butter = measureIngredients("butter", 0.5);
mixIngredients([flour, sugar, eggs, butter]).then();
bakeBatter(batter).then(callback);
}
function prepareBatter() {
console.log("Preparing cake batter...");
console.log(`Measuring flour cups of 1`);
const sugar = measureIngredients("sugar", 1);
const eggs = measureIngredients("eggs", 3);
const butter = measureIngredients("butter", 0.5);
mixIngredients([flour, sugar, eggs, butter]).then();
}
function measureIngredients(ingredient, quantity) {
console.log(`Measuring ${quantity} cups of ${ingredient}`);
return {
ingredient,
quantity,
};
}
function mixIngredients(ingredients) {
console.log("Mixing ingredients together...");
return new Promise((resolve) => {
setTimeout(() => {
console.log("Mixing complete!");
const mixedBatter = {
mixture: ingredients,
consistency: "smooth",
};
resolve(mixedBatter);
}, 3000);
});
}
function bakeBatter(batter) {
console.log("Baking the batter...");
return new Promise((resolve) => {
setTimeout(() => {
console.log("Baking complete!");
const bakedCake = {
batter,
status: "baked",
};
resolve(bakedCake);
}, 5000);
});
}
function frostCake(cake) {
if(cake.status != "baked"){
throw new Error("Cake is not baked!!! Gooey! Mush!")
}
console.log("Frosting the cake...");
cake["status"]= "frosted",
cake["decoration"]= "sprinkles"
const frostedCake = cake
return frostedCake;
}
bakeCake();