From 923330bdfca37c3c360b826826f519a9848ede7f Mon Sep 17 00:00:00 2001 From: Kyrylo Bondarenko Date: Tue, 14 Jan 2025 17:00:01 +0200 Subject: [PATCH] solution --- src/makeCalculator.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/makeCalculator.js b/src/makeCalculator.js index c8297101..e8014ae5 100644 --- a/src/makeCalculator.js +++ b/src/makeCalculator.js @@ -4,7 +4,37 @@ * @return {object} */ function makeCalculator() { - // write code here + return { + result: 0, + + add(value) { + this.result += value; + }, + + subtract(value) { + this.result -= value; + }, + + multiply(value) { + this.result *= value; + }, + + divide(value) { + this.result /= value; + }, + + reset() { + this.result = 0; + + return this; + }, + + operate(callback, value) { + callback.call(this, value); + + return this; + }, + }; } module.exports = makeCalculator;