Как передать свойство (массив
visitinMagazine
уже заполненный true false) в class
Calculation
метод
amountOfVisits
?
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]);
//______Вызываю методы______//
student.getAge();
student1.getAge();
student2.getAge();
student.averageMark();
student1.averageMark();
student2.averageMark();
class Visit extends Student {
constructor(firstName, lastName, yearOfBirth, arrayOfGrades) {
super(firstName, lastName, yearOfBirth, arrayOfGrades);
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('Dmitriy', 'Yaroshchuk', 2001, [70, 80, 90, 100, 90, 90, 99, 100, 95, 100])
const visit1 = new Visit('Andrew', 'Kavetsky', 2000, [90, 90, 90, 90, 90, 90, 100, 100, 95, 93])
const visit2 = new Visit('Diana', 'Koko', 1999, [70, 70, 70, 70, 70, 70, 75, 75, 75, 93])
//______Посейщение уроков______//
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(firstName, lastName, yearsOfBirth, arrayOfGrades) {
super(firstName, lastName, yearsOfBirth, arrayOfGrades);
}
//______Колличество занятий______//
amountOfClasses () {
return console.log(this.arrayOfGrades.length);
}
//______Колличество посищений______//
amountOfVisits () {
return console.log(this.callOfVisitnMagazine.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('Dmitriy', 'Yaroshchuk', 2001, [70, 80, 90, 100, 90, 90, 99, 100, 95, 100])
const calculate1 = new Calculation('Andrew', 'Kavetsky', 2000, [90, 90, 90, 90, 90, 90, 100, 100, 95, 93])
const calculate2 = new Calculation('Diana', 'Koko', 1999, [70, 70, 70, 70, 70, 70, 75, 75, 75, 93])
calculate.amountOfClasses();
calculate1.amountOfClasses();
calculate2.amountOfClasses();
calculate.amountOfVisits(callOfVisitnMagazine);
calculate1.amountOfVisits(callOfVisitnMagazine1);
calculate2.amountOfVisits(callOfVisitnMagazine2);
calculate.summary();
calculate1.summary();
calculate2.summary();