2726. Calculator with Method Chaining
\n\n# Code\njavascript []\nclass Calculator {\n    constructor(value) {\n        this.value = value;\n    }\n\n    add(value) {\n        this.value += value;\n 
\n\n# Code\n```javascript []\nclass Calculator {\n    constructor(value) {\n        this.value = value;\n    }\n\n    add(value) {\n        this.value += value;\n        return this;\n    }\n\n    subtract(value) {\n        this.value -= value;\n        return this;\n    }\n\n    multiply(value) {\n        this.value *= 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.value /= value;\n\n        return this;\n    }\n\n    power(value) {\n        this.value = Math.pow(this.value, value);\n        return this;\n    }\n\n    getResult() {\n        return this.value;\n    }\n}\n\ntry {\n    const cal = new Calculator(10);\n    console.log(cal.add(5).subtract(7).getResult());\n} catch (error) {\n    console.error(error.message);\n}\n\n```
['JavaScript']