Skip to content

Calculator.Calculator

github-actions[bot] edited this page Jan 24, 2024 · 2 revisions

Class: Calculator

Calculator.Calculator

Calculator class for basic arithmetic operations.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Calculator(value?): Calculator

Creates a new calculator.

Parameters

Name Type Default value Description
value number 0 The initial value of the calculator.

Returns

Calculator

Example

const calc = new Calculator();
console.log(calc.value); // 0

Example

const calc = new Calculator(1);
console.log(calc.value); // 1

Defined in

calculator/calculator.ts:35

Properties

value

value: number

The current value of the calculator.

Default

0

Example

const calc = new Calculator();
console.log(calc.value); // 0

Defined in

calculator/calculator.ts:18

Methods

add

add(x): void

Adds a number to the calculator.

Parameters

Name Type Description
x number The number to add.

Returns

void

Method

add

Example

const calc = new Calculator();
calc.add(1);
console.log(calc.value); // 1

Defined in

calculator/calculator.ts:51


div

div(x): void

Divides the calculator by a number.

Parameters

Name Type Description
x number The number to divide by.

Returns

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

Defined in

calculator/calculator.ts:111


mul

mul(x): void

Multiplies the calculator by a number.

Parameters

Name Type Description
x number The number to multiply by.

Returns

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

Defined in

calculator/calculator.ts:89


sub

sub(x): void

Subtracts a number from the calculator.

Parameters

Name Type Description
x number The number to subtract.

Returns

void

Method

sub

Example

const calc = new Calculator();
calc.sub(1);
console.log(calc.value); // -1

Defined in

calculator/calculator.ts:67