-
Notifications
You must be signed in to change notification settings - Fork 0
Calculator.Calculator
github-actions[bot] edited this page Jan 24, 2024
·
2 revisions
Calculator.Calculator
Calculator class for basic arithmetic operations.
• new Calculator(value?
): Calculator
Creates a new calculator.
Name | Type | Default value | Description |
---|---|---|---|
value |
number |
0 |
The initial value of the calculator. |
Example
const calc = new Calculator();
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
console.log(calc.value); // 1
• value: number
The current value of the calculator.
Default
0
Example
const calc = new Calculator();
console.log(calc.value); // 0
▸ add(x
): void
Adds a number to the calculator.
Name | Type | Description |
---|---|---|
x |
number |
The number to add. |
void
Method
add
Example
const calc = new Calculator();
calc.add(1);
console.log(calc.value); // 1
▸ div(x
): void
Divides the calculator by a number.
Name | Type | Description |
---|---|---|
x |
number |
The number to divide by. |
void
Method
div
Example
const calc = new Calculator();
calc.div(2);
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
calc.div(2);
console.log(calc.value); // 0.5
▸ mul(x
): void
Multiplies the calculator by a number.
Name | Type | Description |
---|---|---|
x |
number |
The number to multiply by. |
void
Method
mul
Example
const calc = new Calculator();
calc.mul(2);
console.log(calc.value); // 0
Example
const calc = new Calculator(1);
calc.mul(2);
console.log(calc.value); // 2
▸ sub(x
): void
Subtracts a number from the calculator.
Name | Type | Description |
---|---|---|
x |
number |
The number to subtract. |
void
Method
sub
Example
const calc = new Calculator();
calc.sub(1);
console.log(calc.value); // -1