Skip to content

Commit da16b14

Browse files
callback hell
1 parent 9d04c9c commit da16b14

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// synchronous
2+
3+
// console.log(" I ");
4+
5+
// console.log(" eat ");
6+
7+
// console.log(" ice cream ");
8+
9+
// console.log(" with a ");
10+
11+
// console.log(" spoon ");
12+
13+
// asynchronous
14+
15+
// console.log(" I ");
16+
17+
// console.log(" eat ");
18+
19+
// setTimeout(()=>{console.log(" ice cream ");},4000)
20+
21+
// console.log(" with a ");
22+
23+
// console.log(" spoon ");
24+
25+
26+
27+
// function abcdefg(){}
28+
29+
// let abcdef = ()=>{}
30+
31+
32+
// function one(call_2){
33+
// call_2();
34+
// console.log("Step 1 complete please call step 2");
35+
// }
36+
37+
// function two(){
38+
// console.log("Step 2")
39+
// }
40+
41+
// one(two)
42+
43+
let stocks = {
44+
Fruits: ["strawberry", "grapes", "banana", "apple"],
45+
liquid: ["water", "ice"],
46+
holder: ["cone", "cup", "stick"],
47+
toppings: ["chocolate", "peanuts"],
48+
};
49+
50+
let order = (Fruit_name, callproduction) => {
51+
52+
setTimeout(() => {
53+
console.log(`${stocks.Fruits[Fruit_name]} was selected`)
54+
callproduction();
55+
}, 2000)
56+
57+
};
58+
59+
let production = () => {
60+
61+
setTimeout(() => {
62+
console.log("Production has started")
63+
setTimeout(() => {
64+
console.log("the fruit has been chopped.")
65+
setTimeout(() => {
66+
console.log(`${stocks.liquid[1]} and ${stocks.liquid[0]} was added`);
67+
setTimeout(() => {
68+
console.log(`the machine was started`);
69+
setTimeout(() => {
70+
console.log(`${stocks.holder[0]} was selected`);
71+
setTimeout(()=>{
72+
console.log(`${stocks.toppings[0]}was added as toppings`);
73+
setTimeout(()=>{
74+
console.log(`serve ice cream`)
75+
},2000);
76+
},3000);
77+
}, 2000);
78+
}, 1000);
79+
}, 1000);
80+
}, 2000);
81+
}, 0);
82+
};
83+
84+
order(0, production);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>ice cream</title>
7+
</head>
8+
<body>
9+
10+
<script src="./app.js"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)