Shipping fee function
A bookshop courier charges 35 base units, plus 6 per whole kilogram and 3 per kilometre. Read weight and distance, define a function named shippingFee, and print the calculated charge.
Input
One line containing two integers: weight and distance.
Output
One integer: the complete shipping charge.
Example 1
Input
4 10
Output
89
35 + (4 × 6) + (10 × 3) equals 89.
Constraints
- 1 <= weight <= 100
- 1 <= distance <= 1000
Hints
Hint 1 of 3
A function gives a result back with return.
Hint 2 of 3
Multiply each rate by its matching input.
Hint 3 of 3
Return 35 + weight * 6 + distance * 3.
Solution
Show a reference solution and explanation
function shippingFee(weight, distance) {
return 35 + weight * 6 + distance * 3;
}
const [weight, distance] = readline().split(' ').map(Number);
console.log(shippingFee(weight, distance));
Why it works
The function contains one pricing rule and can be reused with any valid inputs. Returning the result keeps calculation separate from the console output performed by the caller.
Lesson for this exercise: JavaScript Functions: Declarations, Arrows and Return Values