Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const order = true;
- const food = "Hamburger";
- let newOrder = new Promise((resolve, reject) => {
- setTimeout(() => {
- if (order) {
- resolve(`Your ${food} is ready to pick up!`);
- } else {
- reject(Error(`Sorry, we ran out of ${food}`));
- }
- }, 3000);
- });
- newOrder
- .then(value => {
- console.log(value); // The order is set to true so the promise is resolved after 3 seconds.
- //Your Hamburger is ready to pick up!
- })
- .catch(err => console.log(err)); // if the variable order were set to false it will have catched the error.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement