Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. const order = true;
  2. const food = "Hamburger";
  3.  
  4. let newOrder = new Promise((resolve, reject) => {
  5. setTimeout(() => {
  6. if (order) {
  7. resolve(`Your ${food} is ready to pick up!`);
  8. } else {
  9. reject(Error(`Sorry, we ran out of ${food}`));
  10. }
  11. }, 3000);
  12. });
  13.  
  14. newOrder
  15. .then(value => {
  16. console.log(value); // The order is set to true so the promise is resolved after 3 seconds.
  17. //Your Hamburger is ready to pick up!
  18. })
  19. .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