Dry Cleaning Savings Calculator
View Your Savings
Cost per Garment
# of Garments
Total Cost
% savings
Annual savings
//console.log(jQuery(‘#js_pieces_id’).val());
jQuery(‘#js_calculate_button’).on(‘click’,function(){
var our_cost_per_garment = 3.50;
var pieces = parseFloat(jQuery(‘#js_pieces_id’).val());
var total_cost_first = jQuery(‘#js_total_cost_id’).val();
var total_cost = parseFloat(total_cost_first.replace(‘$’,”));
// calculate the cost per garment based on user input
var cost_per = (total_cost / pieces);
if (cost_per > our_cost_per_garment){
// put the number of garments into the two corresponding boxes
jQuery(‘#js-garment-number’).html(pieces);
jQuery(‘#js-garment-number-2’).html(pieces);
// set their cost per garment
jQuery(‘#js-cost-per-garment’).html(‘$’ + cost_per.toFixed(2));
// set our cost per garment
jQuery(‘#js-set-cost-per-garment’).html(‘$’ + our_cost_per_garment);
// figure out our new total cost
var our_total_cost = (our_cost_per_garment * pieces).toFixed(2);
jQuery(‘#js-total-cost-2’).html(‘$’ + our_total_cost);
// set our input total cost from user
jQuery(‘#js-total-cost’).html(‘$’ + total_cost);
// figure out total percentage of savings
var percent_savings = (((total_cost – our_total_cost) / total_cost) * 100);
jQuery(‘#js-percent-savings’).html(percent_savings.toFixed(0) + ‘%’);
// calculate annual savings
var annual_savings = ((total_cost – our_total_cost) * 52);
jQuery(‘#js-annual-savings’).html(‘$’ + annual_savings.toFixed(2));
}else{
alert(“Oops. It looks like you’re getting a good deal on your dry cleaning! You should still give us a try anyway, we have a lot to offer!”);
}
});
Like this:
Like Loading...