Drill

ProblemsJavaScript › pricing

Apply a promo percentage

easypricingJavaScript

The till applies a promo code to a price held in minor units — kuruş, cents, whatever the currency splits into.

discountedPrice(price: int, percent: int) → int

Solve it in the editor →

Where you start

function discountedPrice(price, percent) {
  
}

Worked examples

CallResult
discountedPrice(1000, 20)800
discountedPrice(999, 10)900
discountedPrice(1000, 0)1000
discountedPrice(1000, 150)1000

Hint

Reject the bad range first, then integer-divide.

Reference solution in JavaScript
function discountedPrice(price, percent) {
  if (percent < 1 || percent > 100) return price;
  return price - Math.floor((price * percent) / 100);
}

The same problem in another language

More pricing problems in JavaScript