Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const inventory = {
- sunglasses: 1900,
- pants: 1088,
- bags: 1344
- };
- // Write your code below:
- const myExecutor = (resolve, reject) => {
- if (inventory.sunglasses >0){
- resolve('Sunglasses order processed.');
- }
- else {
- reject('That item is sold out.');
- }
- }
- //Create a function, orderSunglasses(). This function should have no parameters.
- const orderSunglasses = () => {
- return new Promise(myExecutor);
- }
- const orderPromise = orderSunglasses();
- console.log(orderPromise);
- /*
- Output will show:
- 1. if condition is true
- 2. if condition is false - sunglasses is zero
- $ node app.js
- Promise { 'Sunglasses order processed.' }
- $ node app.js
- Promise { <rejected> 'That item is sold out.' }
- (node:1027) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): That item is sold out.
- (node:1027) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
- $
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement