Last active
January 12, 2020 22:16
-
-
Save blarzHernandez/2607707536c9853e121ee4206ce32f83 to your computer and use it in GitHub Desktop.
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
//condition to resolve or reject the promise | |
const isDadHappy = false; | |
//Trumpet promise | |
const trumpet = { | |
brand: "Mendini", | |
model: "MTT-30L", | |
price: 125 | |
}; | |
//Creating the promise | |
const getMyTrumpet = new Promise((resolve, reject) => { | |
if (isDadHappy) { | |
resolve(trumpet); | |
} else { | |
const error = "Dad was not agree with my work"; | |
reject(error); | |
} | |
}); | |
/* He is gonna ask to Dad about the promise for the next days until December 24*/ | |
const askToDad = () => { | |
getMyTrumpet | |
.then(trumpet => { | |
//Congrats my son. You got a really nice trumpet | |
console.log("Wow my trumpet is here", trumpet); | |
}) | |
.catch(error => { | |
console.log("Error", error); | |
}); | |
}; | |
/*He is asking the same question every 3 seconds**/ | |
setInterval(askToDad, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment