Calculator with Method Chaining
IntuitionApproach

Constructor (constructor(value))

Stores the initial number in this.result.



Arithmetic Methods (add,subtract,multiply,divide,power)

Updat
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

1. Constructor (`constructor(value)`)

    - Stores the initial number in this.result.
2. Arithmetic Methods (`add`, `subtract`, `multiply`, `divide`, `power`)

    - Update `this.result`.
    - Return `this` to allow method chaining.
3. Error Handling in `divide()`

    - Throws an error if trying to divide by zero.
4. `getResult()`
- Returns the final computed value.


# Code
```javascript []
class Calculator {
    
    /** 
     * @param {number} value
     */
    constructor(value) {
        this.result = value; // Store the initial value
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    add(value){
        this.result += value;
        return this; // Return the instance for method chaining
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    subtract(value){
        this.result -= value;
        return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */  
    multiply(value) {
        this.result *= value;
        return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    divide(value) {
        if (value === 0){
            throw new Error("Division by zero is not allowed");
        }
        this.result /= value;
        return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    power(value) {
        this.result = Math.pow(this.result, value);
        return this;
    }
    
    /** 
     * @return {number}
     */
    getResult() {
        return this.result;
    }
}
```
['JavaScript']