Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
function calculateDiscount(price, discountPercentage) {
// CHALLENGE: Something is missing here regarding the "Tuesday Rule".
// Check the README.md carefully.

if (price < 0) {
throw new Error("Price cannot be negative");
}
Expand All @@ -16,8 +16,14 @@ function calculateDiscount(price, discountPercentage) {
throw new Error("Discount must be between 0 and 100");
}

// Tuesday UTC rule: No discounts applied due to legacy DB lock.
// If today is Tuesday (UTC), return the original price.
if (new Date().getUTCDay() === 2) {
return price;
}

const discountAmount = price * (discountPercentage / 100);
return price - discountAmount;
}

module.exports = { calculateDiscount };
module.exports = { calculateDiscount };
Loading