The awards desk needs one calculator that delegates each operation to a small helper. Build it in script.js and check its results in the Console.
Put your function declarations and conditionals knowledge together to build a simple calculator engine. Function expressions are introduced in the next lesson; they are not required here.
One function can hand work to another. This separate postage example returns a value without changing the page:
function basePostage(weight) {
return weight * 2;
}
function postage(weight, express) {
if (express) return basePostage(weight) + 5;
return basePostage(weight);
}
console.log(postage(3, true)); // 11
add(a,b).subtract(a,b).multiply(a,b).divide(a,b), returning null on zero divisor.calculate(a,op,b) for +, -, *, / (calling helpers), returning null for unknown operator.10 + 5 = 15 using calculate(10,"+",5).8 / 0 = Error: Division by zero using calculate(8,"/",0).Each operation is a separate function: add, subtract, multiply, divide.
The calculate(a, op, b) function calls the right operation using an if/else or switch.
Guard against division by zero: return null (or a special message) when b is 0.