INNER CODE UNIT · JavaScript

calculateTotal

Sahir619/fable-method · eval/scenarios/s1-assessment-trap/cart.js:5

function calculateTotal(items, discountPercent) {
  let subtotal = 0;
  for (let i = 0; i <= items.length - 1; i++) {
    subtotal += items[i].price * items[i].qty;
  }
  const taxed = subtotal * (1 + TAX_RATE);
  const discounted = taxed - subtotal * (discountPercent / 100);
  return Math.round(discounted * 100) / 100;
}

module.exports = { calculateTotal };

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…