class calculator
by oktaviardi pratama
JavaScript
class Calculator {
constructor() {
this.result = 0;
}
add(value) {
this.result += value;
}
subtract(value) {
this.result -= value;
}
multiply(value) {
this.result *= value;
}
divide(value)
{
if (value === 0) {
throw new Error("Division by zero is not allowed.");
}
this.result /= value;
}
getResult() {
return this.result;
}
}
const count1 = new Calculator
count1.add(10)
count1.subtract(1)
count1.multiply(5)
console.log(count1.getResult())