Clearly✅💯 a simple class solution
Calculator with Method Chaining...\uD83D\uDD25\n- The Calculator class has a constructor that takes an initialValue parameter, which serves as the initial value
## Calculator with Method Chaining...\uD83D\uDD25\n- The Calculator class has a constructor that takes an initialValue parameter, which serves as the initial value of the result.\n```\nconstructor(initialValue) {\n  this.result = initialValue;\n}\n\n```\n- The class has methods for basic mathematical operations: add, subtract, multiply, divide, and power.\nEach of these methods takes a numeric parameter, performs the corresponding operation on the result, and returns the updated Calculator object to allow method chaining.\n- The getResult method simply returns the current value of the result.\n- Method chaining is achieved by making each method return the updated Calculator object (this). This allows consecutive operations to be performed in a single statement.\n```\nclass Calculator {\n  constructor(initialValue) {\n    this.result = initialValue;\n  }\n\n  add(value) {\n    this.result += value;\n    return this;\n  }\n\n  subtract(value) {\n    this.result -= value;\n    return this;\n  }\n\n  multiply(value) {\n    this.result *= value;\n    return this;\n  }\n\n  divide(value) {\n    if (value === 0) {\n      throw new Error("Division by zero is not allowed");\n    }\n    this.result /= value;\n    return this;\n  }\n\n  power(value) {\n    this.result **= value;\n    return this;\n  }\n\n  getResult() {\n    return this.result;\n  }\n}\n\n// Example usage:\nconst myCalculator = new Calculator(0); // Initialize with an initial value\nconst result = myCalculator.add(5).multiply(3).divide(2).power(2).getResult();\nconsole.log(result); // Output: 56.25\n\n```\n> ### I am always happy if it is useful to you\uD83D\uDCC8
[]