Skip to content

Instantly share code, notes, and snippets.

@stariqmi
Created May 15, 2016 17:59
Show Gist options
  • Save stariqmi/67dfcdc8db0663025d7411a7240b4fd5 to your computer and use it in GitHub Desktop.
Save stariqmi/67dfcdc8db0663025d7411a7240b4fd5 to your computer and use it in GitHub Desktop.
Love thy code!
// Render HTML code for an order summary
function order_summary(order_object) {
var price = 0,
tax = 0,
subtotal = '',
html = '';
switch (order_object.price_level) {
case 'free':
// Do nothing, default is 0!
break;
case 'discount':
price = order_object.price - (order_object.discount_percentage * order_object.price);;
break;
case 'sale':
price = order_object.price - order_object.markdown;
break;
default:
price = order_object.price;
}
tax = (order.taxes_applicable == true) ? order_object.taxes : 0;
subtotal = (price === 0) ? 'This order is free' : price;
html += "<p> Product: " + order_object.product_name + "</p>";
html += "<p> Subtotal: $" + subtotal + "</p>";
html += "<p> Tax: $" + tax + "</p>";
html += "<p> Order Total: $" + (price + tax) + "</p>";
document.write("<h1> Order summary </h1>" + html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment