const invalidValueError = new Error('Invalid value'); export default class BMI { constructor(private _weight: number, private _height: number) { } public set height(height: number) { if (height <= 0) console.error(invalidValueError); this._height = height; } public set width(weight: number) { if (weight <= 0) console.error(invalidValueError); this._weight = weight; } public get bmi(): number { return +(this._weight / this._height ** 2).toFixed(2); } public calculateBMI(): string { return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`; } }
- const invalidValueError = new Error('Invalid value');
- export default class BMI {
private _height: number;private _weight: number;constructor(weight: number, height: number) {this._height = height;this._weight = weight;- constructor(private _weight: number, private _height: number) {
- }
set height(height: number) {if (height <= 0) {const invalidValueError = new Error('Invalid value');- public set height(height: number) {
- if (height <= 0)
- console.error(invalidValueError);
}- this._height = height;
- }
set width(weight: number) {if (weight <= 0) {const invalidValueError = new Error('Invalid value');- public set width(weight: number) {
- if (weight <= 0)
- console.error(invalidValueError);
}- this._weight = weight;
- }
get bmi(): number {return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));- public get bmi(): number {
- return +(this._weight / this._height ** 2).toFixed(2);
- }
calculateBMI(): string {- public calculateBMI(): string {
- return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
- }
- }