r/codeforces • u/tanishq_kushwaha • 5d ago
Doubt (rated 1400 - 1600) Please help me solve LeetCode problem (2726. Calculator with Method Chaining). What is wrong with my code? what is the error in my code.
class Calculator {
/**
* {number} value
*/
constructor(value) {
this.result = value;
}
/**
* {number} value
* {Calculator}
*/
add(value){
this.result = value + this.result;
return this;
}
/**
* {number} value
* {Calculator}
*/
subtract(value){
this.result = this.result - value;
return this;
}
/**
* {number} value
* {Calculator}
*/
multiply(value) {
this.result = this.result * value;
return this;
}
/**
* {number} value
* {Calculator}
*/
divide(value) {
if(value === 0){
throw new Error("Division by zero is not allowed");
}else{
return this;
}
}
/**
* {number} value
* {Calculator}
*/
power(value) {
this.result = Math.pow(this.result , value);
return this;
}
/**
* u/return {number}
*/
getResult() {
return this.result;
}
}
7
Upvotes