-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromisetry.js
66 lines (60 loc) · 1.55 KB
/
Promisetry.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
// Use the functions eatBreakfast, eatLunch, eatDinner, and eatDessert to eat your meals in the traditional order.
// Hint: Each function returns a promise
eatBreakfast()
.then(() => eatLunch())
.then(() => eatDinner())
.then(() => eatDessert())
.catch(function(e){
console.log(e)
})
async function(){
try{
await eatBreakfast()
await eatLunch()
await eatDinner()
await eatDessert()
} catch(err){
console.log(err)
}
}
// Do NOT modify below this line until instructed to do so.
function eatBreakfast() {
return new Promise(function(resolve, reject) {
console.log("The eatBreakfast function started executing.")
setTimeout(function() {
addText("You just ate breakfast.")
resolve()
}, 800)
})
}
function eatLunch() {
return new Promise(function(resolve, reject) {
console.log("The eatLunch function started executing.")
setTimeout(function() {
addText("You just ate lunch.")
resolve()
}, 300)
})
}
function eatDinner() {
return new Promise(function(resolve, reject) {
console.log("The eatDinner function started executing.")
setTimeout(function() {
addText("You just ate dinner.")
resolve()
}, 600)
})
}
function eatDessert() {
return new Promise(function(resolve, reject) {
console.log("The eatDessert function started executing.")
setTimeout(function() {
addText("You just ate dessert.")
resolve()
}, 40)
})
}
const textDiv = document.getElementById("text")
function addText(x) {
textDiv.insertAdjacentHTML('beforeend', `<p>${x}</p>`)
}