Проблема код выдает ошибку
mainScripts.js:84 Uncaught TypeError: Cannot read properties of undefined (reading 'length') at Calculation.amountOfClasses (mainScripts.js:84:36) at mainScripts.js:109:11
Не понимаю как данную ошибку устранить.
Мой код:
class Student {
constructor(firstName,lastName,yearOfBirth,arrayOfGrades) {
this.firstName = firstName;
this.lastName = lastName;
this.yearOfBirth = yearOfBirth;
this.arrayOfGrades = arrayOfGrades;
}
//______Возраст студента______//
getAge () {
return console.log(`${this.firstName}'s old is ${2023 - this.yearOfBirth} years`);
}
//______Средний бал______//
averageMark () {
let sum = 0;
for (let i = 0; i < this.arrayOfGrades.length; i++) {
sum = sum + this.arrayOfGrades[i];
}
return console.log(`${this.firstName}'s average mark is ${sum / this.arrayOfGrades.length}`);
}
}
//______Экземпляры студентов______//
const student = new Student('Dmitriy','Yaroshchuk',2001,[70,80,90,100,90,90,99,100,95,100]);
const student1 = new Student('Andrew','Kavetsky',2000,[90,90,90,90,90,90,100,100,95,93]);
const student2 = new Student('Diana','Koko',1999,[70,70,70,70,70,70,75,75,75,93]);
//______Проверка что arrayOfGrades является массивом_____//
// console.log(student.arrayOfGrades);
// console.log(typeof student.arrayOfGrades);
// console.log(Array.isArray(student.arrayOfGrades));
// const spreadArrayOfGrades = [...(student.arrayOfGrades)];
// const spreadArrayOfGrades1 = [...(student1.arrayOfGrades)];
// const spreadArrayOfGrades2 = [...(student2.arrayOfGrades)];
// console.log(spreadArrayOfGrades);
// console.log(spreadArrayOfGrades1);
// console.log(spreadArrayOfGrades2);
//______Вызываю методы______//
student.getAge();
student1.getAge();
student2.getAge();
student.averageMark();
student1.averageMark();
student2.averageMark();
class Visit extends Student {
constructor() {
super();
this.visitinMagazine = [];
}
//______Используется когда студент был на занятие______//
present () {
if (this.visitinMagazine.length < 26) {
this.visitinMagazine.push(true);
return this;
} else {
return this.visitinMagazine.pop();
}
}
//______Используется когда студент НЕ был на занятие______//
absent () {
if (this.visitinMagazine.length < 26) {
this.visitinMagazine.push(false);
return this;
} else {
return this.visitinMagazine.pop();
}
}
}
//______Экземпляры посейщения______//
const visit = new Visit();
const visit1 = new Visit();
const visit2 = new Visit();
//______Посейщение уроков______//
visit.present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().absent().absent();
const callOfVisitnMagazine = [...(visit.visitinMagazine)];
// console.log(callOfVisitnMagazine);
//______Посейщение уроков______//
visit1.absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().present().present();
const callOfVisitnMagazine1 = [...(visit1.visitinMagazine)];
// console.log(callOfVisitnMagazine1);
//______Посейщение уроков______//
visit2.present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().absent().absent().absent();
const callOfVisitnMagazine2 = [...(visit2.visitinMagazine)];
// console.log(callOfVisitnMagazine2);
class Calculation extends Visit {
constructor(arrayOfGrades,visitinMagazine) {
super(arrayOfGrades,visitinMagazine);
}
//______Колличество занятий______//
amountOfClasses () {
return console.log(this.arrayOfGrades);
}
//______Колличество посищений______//
amountOfVisits () {
return console.log(this.visitinMagazine.filter((element) => element === true).length);
}
//______Проверяем среднюю оценку и посейщение______//
summary () {
const averageVisit = this.amountOfVisits / this.amountOfClasses;
if (this.averageMark > 90 && averageVisit > 0.9) {
return console.log('Cool!');
} else if (this.averageMark > 90 || averageVisit > 0.9) {
return console.log('Good, but it can be better!');
} else {
return console.log('Radish');
}
}
}
//______Экземпляры расчетов______//
const calculate = new Calculation([70,80,90,100,90,90,99,100,95,100],callOfVisitnMagazine);
const calculate1 = new Calculation([90,90,90,90,90,90,100,100,95,93],callOfVisitnMagazine1);
const calculate2 = new Calculation([70,70,70,70,70,70,75,75,75,93],callOfVisitnMagazine2);
calculate.amountOfClasses();
calculate1.amountOfClasses();
calculate2.amountOfClasses();
calculate.amountOfVisits();
calculate1.amountOfVisits();
calculate2.amountOfVisits();
calculate.summary();
calculate1.summary();
calculate2.summary();