-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestPromsie.html
More file actions
144 lines (136 loc) · 5.24 KB
/
testPromsie.html
File metadata and controls
144 lines (136 loc) · 5.24 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- JQuery CDN 3.6 -->
<script src="https://code.jquery.com/jquery-3.6.0.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!-- personal custom CSS-->
<title>Hello, Fierem!</title>
</head>
<body>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<!--Personal custom JS script-->
<script>
// fetch('https://api.github.com/users')
// .then(response => console.log(response))
// .catch(error => console.error(error));
// const myPromise = fetch('https://api.github.com/users');
// myPromise.then(response => console.log(response));
// myPromise.catch(error => console.error(error));
// const githubPromise = fetch('https://api.github.com/repositories');
// const bitbucketPromise = fetch('https://api.bitbucket.org/2.0/repositories');
//
// Promise.all([githubPromise, bitbucketPromise])
// .then(function(data) {
// console.log(data);
// // here data is an array of the resolved values from each promise
// // we can now do something with both pieces of data
// })
// .catch(function(error) {
// console.log(error);
// // handle errors
// });
// Promise.resolve('one').then((one) => {
// console.log(one);
// return 'two';
// }).then((two) => {
// console.log(two);
// return 'three';
// }).then((three) => {
// console.log(three);
// });
// fetch('https://api.github.com/users').then( response => {
// response.json().then( users => {
// users.forEach( user => {
// // do something with each user object...
// console.log(user);
// });
// });
// });
// fetch('https://api.github.com/users').then( response => {
// response.json().then( users => {
// users.forEach( userObj => {
// // do something with the username login
// console.log(userObj.login);
// });
// });
// });
// fetch('https://api.github.com/users')
// .then(response => response.json())
// .then(users => {
// users.forEach( userObj => {
// // do something with each username
// console.log(userObj.login);
// })
// })
// .catch(error => console.error(error));
// const myPromise = new Promise((resolve, reject) => {
// if (Math.random() > 0.5) {
// resolve();
// } else {
// reject();
// }
// });
//
// myPromise.then(() => console.log('resolved!'));
// myPromise.catch(() => console.log('rejected!'));
// const myPromise = new Promise((resolve, reject) => {
// setTimeout(() => {
// if (Math.random() > 0.5) {
// resolve();
// } else {
// reject();
// }
// }, 1500);
// });
//
// console.log(myPromise); // a pending promise
//
// myPromise.then(() => console.log('resolved!'));
// myPromise.catch(() => console.log('rejected!'));
// function makeRequest() {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// if (Math.random() > 0.1) {
// resolve('Here is your data: ...');
// } else {
// reject('Network Connection Error!');
// }
// }, 1500);
// });
// }
//
// const request = makeRequest();
// console.log(request); // pending promise
// request.then(message => console.log('Promise resolved!', message));
// // if resolved, will log "Promise resolved!" and "Here is your data: ..."
// request.catch(message => console.log('Promise rejected!', message));
// // if rejected, will log "Promise rejected!" and "Network Connection Error!"
function makeRequest() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.1) {
resolve('Here is your data: ...');
} else {
reject('Network Connection Error!');
}
}, 1500);
});
}
const request = makeRequest();
console.log(request); // pending promise
request.then(message => console.log('Promise resolved!', message));
// if resolved, will log "Promise resolved!" and "Here is your data: ..."
request.catch(message => console.log('Promise rejected!', message));
// if rejected, will log "Promise rejected!" and "Network Connection Error!"
</script>
</body>
</html>