-
Notifications
You must be signed in to change notification settings - Fork 0
/
promises.js
61 lines (52 loc) · 1.17 KB
/
promises.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
'use strict'
let myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Good to go!');
}, 500);
setTimeout(() => {
reject('uh oh');
}, 1000);
});
myPromise
.then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});
myPromise
.then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
let myPromise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Good to go! 1');
}, 500);
});
let myPromise2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Good to go! 2');
}, 1000);
});
let myPromise3 = new Promise((resolve, reject) => {
setTimeout(() => {
reject('uh oh! 3');
}, 5000);
});
Promise.all([myPromise1, myPromise2, myPromise3])
.then((data) => {
console.log(data);
},(err) => {
console.log(err);
});
fetch('http://apiicndb.com/jokes/random/10')
.then((response) => {
response.json()
.then((json) => {
console.log(json);
});
})
.catch((error) => {
console.log(error);
});