Date: 2024-12-09 19:11:54
Score: 0.5
Natty:
// Remove the discount from the price to get the true base price
const price = parseFloat(priceText.replace(/[^0-9.]/g, ''));
const quantity = parseInt(customQuanityField.value) || 1;
// Find current discount if any
let currentDiscount = 0;
for (const range in productDiscounts) {
const [min, max] = range.split(' - ').map(Number);
if (quantity >= min && quantity <= max) {
currentDiscount = productDiscounts[range];
break;
}
}
// Return the original base price by removing the discount
return price / (1 - currentDiscount / 100);
Reasons:
- Long answer (-0.5):
- Has code block (-0.5):
- Self-answer (0.5):
- Low reputation (1):
Posted by: Alex McIver