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
result
property is initially 0.
How the calculator will work:
- Each
operate
call takes a callback and a number and sets the appropriate value to theresult
property. - The
reset
method resetsresult
value to 0. add
,subtract
,multiply
,divide
are passed as callbacks tooperate
method.- The
operate
andreset
methods 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