-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodewarsChallenge52.js
More file actions
26 lines (22 loc) · 842 Bytes
/
codewarsChallenge52.js
File metadata and controls
26 lines (22 loc) · 842 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
// Create a function to display the result
function myDisplay(message) {
console.log(message); // Display the message in the console
}
// Create a Promise Object
let myPromise = new Promise(function(myResolve, myReject) {
let result = true; // Simulate an operation result
// Code that may take some time goes here
// For example, you can use setTimeout to simulate delay.
setTimeout(() => {
if (result == true) {
myResolve("OK"); // Resolve the promise with "OK"
} else {
myReject("Error"); // Reject the promise with "Error"
}
}, 1000); // Simulate 1 second delay
});
// Using then() to display result
myPromise.then(
x => myDisplay(x), // Handle resolved promise
x => myDisplay(x) // Handle rejected promise
);