Simple Solution with explanation of the program and approach to solve the problem step by step
IntuitionUnderstand the given condition and think the logic to the given problem and the return value.ApproachWe just need a basic math calculation and operatio
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Understand the given condition and think the logic to the given problem and the return value.
# Approach
<!-- Describe your approach to solving the problem. -->
We just need a basic math calculation and operations to solve this question.We have a class `Calculator` with its methodes and We also have number `value`. On these value we perforn the opration like add, subtract, division, etc.
We have to return the error if value is 0 in division part.
# Program Breakdown
**This is the breakdown of the program given bellow of this page**
- First we need to intialise a first number using the constructor `Calculator` which take the argument `value` so we use `this.value = value` which initilize the first value, `this.error = 0` this is used to indicate the error if it appears, we initilize `0` because we don't have any error in the constructor
- To add the value we use `add()` method which accept the argument `value` and `this.value += value` which is in the form of `this.value = this.value + value` perform the addition and return `this` enables **method chaining.**
- All the method of the `Calculator` class use the same method .But we have some different things in methods :-
1. divide
2. power
- In the `divide` method we if the value is 0 we cannot divivde any other value by 0 so there is an error to solve that we use if condition to check the value of `value` is 0 or not if it is 0 we use `this.error` we created above and intialize its value by `this.error = "Division by zero is not allowed"`.
- If there is no error we prosed with `this.value /= value`.
- The power method use the `Math` to find the power because there is no operator for this `this.value = Math.pow(this.value, value)`.
- `getResult()` return the result when it is called if there is any error it return error if not it return result stored in `value`.
# Complexity 
- Time complexity: $$O(1)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
Calculator class is generally O(1) for each operation (add, subtract, multiply, divide, power). This is because each method performs a constant-time arithmetic operation regardless of the size of the input. 
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
since the class maintains a fixed amount of state (the value and error properties) regardless of the number of operations performed or the size of the input values. 
# Code
```javascript []
class Calculator {

    constructor(value) {
        this.value = value
        this.error = 0
    }

    add(value) {
        this.value += value
        return this
    }

    subtract(value) {
        this.value -= value
        return this
    }

    multiply(value) {
        this.value *= value
        return this
    }

    divide(value) {
        if (value === 0) {
            this.error = "Division by zero is not allowed"
        } else {
            this.value /= value
        }
        return this
    }

    power(value) {
        this.value = Math.pow(this.value, value)
        return this
    }

    getResult() {
        if (this.error) {
            return this.error
        }
        return this.value
    }
}
```

# HAVE A NICE CODING DAY
['JavaScript']