Read the guideline before start
❗️❗️❗️ DON'T FORGET TO PROOFREAD YOUR CODE WITH CHECKLIST BEFORE SENDING YOUR PULL REQUEST❗️❗️❗️
Another calculator. Now the task is more difficult.
Create a makeCalculator function that returns an object that
has the following fields:
- Methods:
add,subtract,multiply,divide,reset,operate. - The
resultproperty is initially 0.
How the calculator will work:
- Each
operatecall takes a callback and a number and sets the appropriate value to theresultproperty. - The
resetmethod resetsresultvalue to 0. add,subtract,multiply,divideare passed as callbacks tooperatemethod.- The
operateandresetmethods can be called in a chain.
Example:
const calculator = makeCalculator();
calculator.operate(calculator.add, 21)
console.log(calculator.result); // 21
calculator.reset()
console.log(calculator.result); // 0
calculator
.operate(calculator.add, 10)
.reset()
.operate(calculator.subtract, 20)
.operate(calculator.divide, 5)
.operate(calculator.multiply, 7)
console.log(calculator.result); // -28