From 3d7d6b63e4c9297efb3cebf6847fede9a21713b5 Mon Sep 17 00:00:00 2001 From: Andrii Zakharenko Date: Thu, 18 Jul 2024 00:18:02 +0300 Subject: [PATCH] Solution --- src/makeCalculator.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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;