forked from rohan-paul/Awesome-JavaScript-Interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-code.js
More file actions
30 lines (27 loc) · 682 Bytes
/
Copy pathtest-code.js
File metadata and controls
30 lines (27 loc) · 682 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
const isMomHappy = true;
// Define a function to return a Promise
const willIGetNewPhone = new Promise((resolve, reject) => {
if (isMomHappy) {
const phone = {
brand: "Samsung",
color: "black"
};
resolve(phone);
} else {
const reason = new Error("Mom is not happy");
reject(reason);
}
});
const showOff = phone => {
const message =
"Hey friend, I have a new " + phone.color + " " + phone.brand + " phone";
return Promise.resolve(message);
};
// call out promise
const askMom = () => {
willIGetNewPhone
.then(showOff)
.then(fullfilled => console.log(fullfilled))
.then(error => console.log(error.message));
};
askMom();