TomWalbridge,
function cart(basketAmount, countGoods, promo = null) {
let discountAmount = 0;
let rules = [
() => {
if (promo === "ДАРИМ300") discountAmount += 300;
},
() => {
if (countGoods >= 10) discountAmount += basketAmount * .05;
},
() => {
if (basketAmount > 50000) discountAmount += (basketAmount - 50000) * 0.2;
},
() => {
if (promo === "СКИДКА15" && basketAmount >= 20000) discountAmount += basketAmount * 0.15;
}
];
for (let f of rules) f();
let result = Math.max(0, basketAmount - discountAmount);
return result;
}
console.log(cart(80000, 20, "СКИДКА15"));