Drill

ProblemsJavaScript › logistics

What does this parcel cost to send

easylogisticsJavaScript

A courier prices every parcel as: the first five kilograms cost 300 (minor units) and each further kilogram adds 60.

parcelCost(weight: int) → int

Solve it in the editor →

Where you start

function parcelCost(weight) {
  
}

Worked examples

CallResult
parcelCost(3)300
parcelCost(5)300
parcelCost(6)360
parcelCost(10)600

Hint

Subtract the free five, multiply what is left, and add the base.

Reference solution in JavaScript
function parcelCost(weight) {
  if (weight < 0) return 0;
  return 300 + Math.max(0, weight - 5) * 60;
}

The same problem in another language

More logistics problems in JavaScript