|
| 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); |
0 commit comments