Put your functions, arrow functions, and conditionals knowledge together to build a simple calculator engine.
Build the following pure functions in script.js:
add(a, b) — returns a + bsubtract(a, b) — returns a - bmultiply(a, b) — returns a * bdivide(a, b) — returns a / b; if b is 0 return nullcalculate(a, op, b) — delegates to the right function based on the op string ("+", "-", "*", "/"); returns null for an unknown operator.Then:
calculate(10, "+", 5) and display in #result as "10 + 5 = 15".calculate(8, "/", 0) and display in #zero-result as "8 / 0 = Error: Division by zero".The index.html already has <p id="result"> and <p id="zero-result"> ready for you.
Each operation is a separate function: add, subtract, multiply, divide.