-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromise.js
More file actions
105 lines (102 loc) · 3.28 KB
/
promise.js
File metadata and controls
105 lines (102 loc) · 3.28 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//Problem: Make a process that can calculate a student course progress
//Use "promise" to solve this problem
////In this processs you can define 3 situation such as "pyment, study progress, getting certificate"
{
// const sPayment = true;
// const sMarks = 90;
// function payment() {
// console.log(`Payment method is in progess....`);
// const promise1 = new Promise(function (resolve, reject) {
// setTimeout(function () {
// if(sPayment === true) {
// resolve();
// }
// else {
// reject("Payment failed!");
// }
// }, 2000)
// })
// return promise1;
// }
// function progress() {
// console.log(`Course is in progress>>>>>`);
// const promise2 = new Promise(function (resolve, reject) {
// setTimeout(function () {
// if(sMarks >= 80) {
// resolve();
// }
// else {
// reject(`You don't have enough marks to get the certificate :(`);
// }
// }, 3000)
// })
// return promise2;
// }
// function certificate() {
// console.log(`Preparing your certificate.......`);
// const promise3 = new Promise(function (resolve) {
// setTimeout(function () {
// resolve(`Congratulations for your achievevment :)`);
// }, 1000)
// })
// return promise3;
// }
// payment()
// .then(progress)
// .then(certificate)
// .then(function (value) {
// console.log(value);
// })
// .catch(function (err) {
// console.log(err);
// })
}
{
//Define a school study plan and excute all the situation in 3 step:
let studentAddmission = true;
let allSemesterDone = true;
function addmissionProcess() {
console.log(`Addmission is in progress>>>>`);
const promise1 = new Promise(function (res, rej) {
setTimeout(function () {
if(studentAddmission) {
res();
} else {
rej("You failed to get addimission in our institute! Better luck next time.");
}
}, 1000)
})
return promise1;
}
function semesterProgress() {
console.log(`Semester is in progress.....`);
const promise2 = new Promise(function (resolve, reject) {
setTimeout(function () {
if(allSemesterDone) {
resolve();
} else {
reject("You have to pay money to get addmission again :(")
}
}, 15000)
})
return promise2;
}
function gratuating() {
console.log(`Preparing your certificate!`);
const promise3 = new Promise(function (re) {
setTimeout(function () {
re(`Congratulation for your long journy with us, wish you a bright future.`)
}, 3000)
})
return promise3;
}
addmissionProcess()
.then(semesterProgress)
.then(gratuating)
.then(function (value) {
console.log(value);
})
.catch(function (error) {
console.log(error);
})
}