Skip to content

Instantly share code, notes, and snippets.

@muhammadqazi
Created February 15, 2024 19:49
Show Gist options
  • Save muhammadqazi/5e47320897c1f1f317eb68b60e2753d3 to your computer and use it in GitHub Desktop.
Save muhammadqazi/5e47320897c1f1f317eb68b60e2753d3 to your computer and use it in GitHub Desktop.
Dream :/
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