diff --git a/src/makeCalculator.js b/src/makeCalculator.js index c8297101..c598fcdc 100644 --- a/src/makeCalculator.js +++ b/src/makeCalculator.js @@ -4,7 +4,43 @@ * @return {object} */ function makeCalculator() { - // write code here + const calculator = { + result: 0, + add(operand) { + this.result += operand; + + return this; + }, + subtract(operand) { + this.result -= operand; + + return this; + }, + multiply(operand) { + this.result *= operand; + + return this; + }, + divide(operand) { + if (operand !== 0) { + this.result /= operand; + } + + return this; + }, + reset() { + this.result = 0; + + return this; + }, + operate(callback, number) { + callback.call(this, number); + + return this; + }, + }; + + return calculator; } module.exports = makeCalculator;