Easy!! Thank me later :) - Calculator with Method Chaining
IntuitionMy first thought when i see the problem is we need to understand about the object oriented programming first, then we will know how to fill the empty m
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
My first thought when i see the problem is we need to understand about the object oriented programming first, then we will know how to fill the empty method in the problem.

# Approach
<!-- Describe your approach to solving the problem. -->
- Initialize the value in the constructor, we can say this is the storage that the value we can update by the methods.
- add(value): update the value in constructor by adding the value from param
- substract(value): update the value in constructor by substracting the value from param
- multiply(value): update the value in constructor by multiplying the value from param
- divide(value): update the value in constructor by dividing the value from param, but if the parameter is zero, we should throw an error message because we don't handle dividing by 0
- power(value): update the value in constructor by powering the value from param
- getResult(): return the value from constructor

# Complexity
##### Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- add: O(1)
- subtract: O(1)
- multiply: O(1)
- divide: O(1)
- power: O(1)
- getResult: O(1)

##### Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
- add: O(1)
- subtract: O(1)
- multiply: O(1)
- divide: O(1)
- power: O(1)
- getResult: O(1)

# Code
```javascript []
class Calculator {

    /** 
     * @param {number} value
     */
    constructor(value) {
        this.result = value
    }

    /** 
     * @param {number} value
     * @return {Calculator}
     */
    add(value) {
        this.result += value
        return new Calculator(this.result)
    }

    /** 
     * @param {number} value
     * @return {Calculator}
     */
    subtract(value) {
        this.result -= value
        return new Calculator(this.result)
    }

    /** 
     * @param {number} value
     * @return {Calculator}
     */
    multiply(value) {
        this.result *= value
        return new Calculator(this.result)
    }

    /** 
     * @param {number} value
     * @return {Calculator}
     */
    divide(value) {
        if (value === 0) {
            throw 'Division by zero is not allowed'
        } else {
            this.result /= value
        }
        return new Calculator(this.result)
    }

    /** 
     * @param {number} value
     * @return {Calculator}
     */
    power(value) {
        this.result = Math.pow(this.result, value)
        return new Calculator(this.result)
    }

    /** 
     * @return {number}
     */
    getResult() {
        return this.result
    }
}
```
['JavaScript']