Почему говорят, что объем не определен? - PullRequest
0 голосов
/ 24 мая 2019

Получение ошибки о недопустимом возврате на томе ...

попытался добавить CuboidMaker15.volume для вызова объекта

class CuboidMaker15 {
    constructor(cuboidMaker15Attributes){
      this.length = cuboidMaker15Attributes.length;
      this.width = cuboidMaker15Attributes.width;
      this.height = cuboidMaker15Attributes.height;
    }
}
   volume(); {
    return this.length * this.width * this.height;
  }

surfaceArea(); {
  return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
}

const cuboid15 = new CuboidMaker15({
  length: 4,
  width: 5,
  height: 5
});

Говорит, что объем не определен ...

1 Ответ

2 голосов
/ 24 мая 2019

Вам нужно переместить ваши методы в определение класса. Также избавьтесь от ; после имени метода:

class CuboidMaker15 {
  constructor(cuboidMaker15Attributes) {
    this.length = cuboidMaker15Attributes.length;
    this.width = cuboidMaker15Attributes.width;
    this.height = cuboidMaker15Attributes.height;
  }
  volume() {
    return this.length * this.width * this.height;
  }

  surfaceArea() {
    return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
  }
}

const cuboid15 = new CuboidMaker15({
  length: 4,
  width: 5,
  height: 5
});


console.log(cuboid15);
console.log(cuboid15.volume());
console.log(cuboid15.surfaceArea());
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...