Created
February 15, 2024 19:49
-
-
Save muhammadqazi/5e47320897c1f1f317eb68b60e2753d3 to your computer and use it in GitHub Desktop.
Dream :/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function achieve(dream) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const successRate = Math.random(); | |
if ( | |
dream.size === "BIG" && | |
dream.priority === "HIGH" && | |
successRate > 0.5 | |
) { | |
resolve("Congratulations! Dream achieved!"); | |
} else { | |
reject("Dream not achieved. Work harder!"); | |
} | |
}, 2000); | |
}); | |
} | |
const myDream = { | |
size: "BIG", | |
priority: "HIGH" | |
}; | |
function planNextStep() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve("Start executing the plan!"); | |
}, 1000); | |
}); | |
} | |
console.log("Attempting to achieve dream..."); | |
achieve(myDream) | |
.then(message => { | |
console.log(message); | |
return planNextStep(); | |
}) | |
.then(nextStep => { | |
console.log("Next step planned:", nextStep); | |
}) | |
.catch(error => { | |
console.error("Error:", error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment