JSFiddle - React, Tailwind, and code Playground

by kshep92

HTML

Value <br /> 
$ <input type="text" id="value" value="600"/> <br />
Special Price <br /> 
$ <input type="text" id="specialPrice" value="425"/> <br />
Discount <br />
<input type="text" id="discount" /> % <br />
Savings <br />
$ <input type="text" id="savings" /> <br />
Coupon Price <br />
$ <input type="text" id="couponPrice" /> <br />
<button>Calculate</button>

JavaScript

$(document).ready(function() {
    $("button").click(function() {
        var value = $("#value").val();
        var special = $("#specialPrice").val();
        var discount = Math.round((value-special)/value * 100);
        var savings = value - special;
        $("#discount").val(discount);
        $("#savings").val(savings);
        var couponPrice = 0;
        switch(true) {
            case (savings >= 20 && savings < 100):
                couponPrice = Math.round(0.05 * savings);
                break;
            case (savings >= 100):
                couponPrice = Math.round(0.08 * savings);
                break;
        }
        $("#couponPrice").val(couponPrice);
    });
});