forked from benrbryant/JavaScript_Promises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (36 loc) · 792 Bytes
/
app.js
File metadata and controls
41 lines (36 loc) · 792 Bytes
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
'use strict';
/*
function watchTutorialCallback(callback, errorCallback) {
let userLeft = false;
let userWatchingLiveStream = true;
if (userLeft) {
errorCallback({
name: "User Left",
message: ":(",
});
} else if (userWatchingLiveStream) {
callback("Thumbs up and Subscribe");
}
}
watchTutorialCallback(
(message) => {
console.log(message);
},
(error) => {
console.log(error.name + " " + error.message);
}
);
*/
let watching = new Promise((resolve, reject) => {
let userWatchingLiveStream = Math.round(Math.random());
if(userWatchingLiveStream) {
resolve('Thumbs up and subscribe!');
} else {
reject('User left');
}
});
watching.then(message => {
console.log(message);
}).catch(message => {
console.warn(message);
});