0๐
โ
If it were me, I would store key-value pairs in a pricing object where the key is the upper or lower limit for a quantity price, and the value is the upper/lower limit for the price multiplier. Like this:
var pricingMap = {36: 1, 72: 0.85, 144: 0.75, 288: 0.65};
function getDiscount(qty){
for (var upper in pricingMap) {
if (parseInt(this.qty, 10) < upper)
return pricingMap[upper];
}
}
This way, it is simple to add more quantity ranges and discounts.
Source:stackexchange.com