Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.






                /* FOR REFERENCE 
var couponDBVals = {
  id: 1,
  name: '10OFF',
  couponExpiry: null,
  initialDiscountPercentage: 5,
  initialDiscountValue: 100,
  minWatermark: 500,

  maxWatermark: 1000,
  maxWatermarkDiscountPercentage: 10,
  maxWatermarkDiscountValue: 200,

  renewalLength: null,
  status: 'active'

cartItem = {
    subtotal: 454.55,
    tax: 45.45,
    totalNoFees: 500,
    total: 1500
var total =;
var storedCoupon = 'HELLOWORLD';
var customerCoupon = 'OO';
var discountAmount = 0;
var absoluteDiscount;
if (customerCoupon === storedCoupon) {
  calculateDiscount(couponDBVals, total);
// Coupon Function
// working to create some cases for various coupons
function calculateDiscount(options, total) {
  var absoluteTotal = total;
  var discount = 0;
  // Min Watermark Discount Values
  var initialDiscVal = options.initialDiscountValue;
  var initialDiscPercent = options.initialDiscountPercentage;
  // High Watermark Discount Values
  var maxWmarkDiscVal = options.maxWatermarkDiscountValue;
  var maxWmarkDiscPercent = options.maxWatermarkDiscountPercentage;
  // Calculate discount from a percentage value
  function getDiscountFromPercentage(value, percentage) {
    return (value / 100) * percentage;

  function findDiscount(percent, val) {
    discount = getDiscountFromPercentage(absoluteTotal, percent);
    // if the discount value is greater than the maximum disocunt amount
    if (discount >= val) {
      // discount is now the maximum discount amount
      discount = val;

  // Basic Case with Min Watermark
  if (absoluteTotal >= options.minWatermark && options.maxWatermark === null) {
    // basic formula to find discount value
    findDiscount(initialDiscPercent, initialDiscVal);

  // Case with Max Watermark
  if (absoluteTotal >= options.maxWatermark && options.maxWatermark !== null) {
    findDiscount(maxWmarkDiscPercent, maxWmarkDiscVal);

  return discount;

absoluteDiscount = calculateDiscount(couponDBVals, total);
console.log("$" + absoluteDiscount);
// end Coupon Function