Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function submitOrder(user) {
- var shoppingCart, zipCode, shippingRate, orderSuccessful;
- // Get the current user's shopping cart
- OrderAPI.getShoppingCartAsync(user)
- .then(function(cart) {
- shoppingCart = cart;
- return CustomerAPI.getProfileAsync(user);
- })
- .then(function(profile) {
- // Also look up the ZIP code from their profile
- zipCode = profile.zipCode;
- })
- .then(function(x) {
- // Calculate the shipping fees
- shippingRate = calculateShipping(shoppingCart, zipCode);
- return OrderAPI.placeOrderAsync(shoppingCart, shippingRate);
- })
- .then(function(success) {
- orderSuccessful = success;
- });
- // Submit the order
- console.log(`Your order ${orderSuccessful? "was" : "was NOT"} placed successfully`);
- }
- //The same thing with async await (someone else's solution)
- async function submitOrder2(user) {
- let shoppingCart, zipCode, shippingRate, orderSuccessful;
- // Get the current user's shopping cart
- shoppingCart = await OrderAPI.getShoppingCartAsync(user);
- // Also look up the ZIP code from their profile
- zipCode = (await CustomerAPI.getProfileAsync(user)).zipCode;
- // Calculate the shipping fees
- shippingRate = calculateShipping(shoppingCart, zipCode);
- // Submit the order
- orderSuccessful = await OrderAPI.placeOrderAsync(shoppingCart, shippingRate);
- console.log(`Your order ${orderSuccessful? "was" : "was NOT"} placed successfully`);
- }
Add Comment
Please, Sign In to add comment