The Negative-Price Flash Sale — JavaScript Bug Hunt
Inspired by the seasonal-sale pricing bugs that turn storefronts into charities: stacking a 50% banner discount with a 75% coupon by adding the percentages…
- Language: JavaScript
- Layer: Backend
- Difficulty: Easy
- Concepts: Pricing, Math
- Modelled on: Steam-class sales
- Visible tests: stacked discounts compound, never sum; a single discount is simple
- Reward: 50 XP for a complete fix
Briefing
Inspired by the seasonal-sale pricing bugs that turn storefronts into charities: stacking a 50% banner discount with a 75% coupon by adding the percentages takes 125% off. The store briefly paid customers to take games.
Discounts compound multiplicatively — fix discounts.js.
Bug report
BUG-125PCT · Priority: Critical · Reported by: storefront
applyDiscounts(priceCents, percents):
- apply each percentage to the RUNNING price (integer floor each step)
- 1000 with [50, 75] -> 500 -> 125
Observed: percentages are summed first — [50, 75] takes 125% off and the checkout total goes negative.
Logs
[cart] total: -250 cents ("you earn $2.50 buying this")The code as shipped
src/store/discounts.js (editable)
// Applies stacked percentage discounts to a price in cents.
exports.applyDiscounts = function (priceCents, percents) {
var totalPercent = 0;
for (var i = 0; i < percents.length; i++) {
totalPercent += percents[i];
}
return Math.floor(priceCents * (100 - totalPercent) / 100);
};
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.