-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
90 lines (66 loc) · 2.25 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// JavaScript ES6
class School {
constructor(name, level, numberOfStudents){
this._name = name;
this._level = level;
this._numberOfStudents = numberOfStudents;
}
get name(){
return this._name;
}
get level(){
return this._level;
}
get numberOfStudents(){
return this._numberOfStudents;
}
set numberOfStudents(num){
if (num.isNan){
console.log('Invalid input: numberOfStudents must be set to a Number.')
} else {
this._numberOfStudents = num;
}
} // Fin numberOfStudents(num)
quickFacts(){
console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.`)
} // quickFacts()
static pickSubstituteTeacher(subTeachers){
const index = Math.floor(subTeachers.length * Math.random());
return subTeachers[index];
} // pickSubstituteTeacher()
}
class PrimarySchool extends School {
constructor(name, numberOfStudents, pickupPolicy){
super(name, "primary", numberOfStudents);
this._pickupPolicy = pickupPolicy;
}
get pickupPolicy(){
return this._pickupPolicy;
}
} // PrimarySchool
class HighSchool extends School {
constructor(name, numberOfStudents, sportsTeams){
super(name, "high", numberOfStudents, sportsTeams);
this._sportsTeams = sportsTeams;
}
get sportsTeams(){
return this._sportsTeams;
}
} // HighSchool
class MiddleSchool extends School{
constructor(name, numberOfStudents){
super(name, "middle", numberOfStudents);
}
} // MiddleSchool
const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.');
//console.log(lorraineHansbury);
lorraineHansbury.quickFacts();
const sub = School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
console.log("Substitute teacher: " + sub);
const alSmith = new HighSchool('Al E. Smith', 415,['Baseball', 'Basketball', 'Volleyball', 'Track and Field'])
//console.log(alSmith);
alSmith.quickFacts();
console.log(alSmith.sportsTeams);
const innsmouthMiddle = new MiddleSchool("Innsmouth Middle", 560);
innsmouthMiddle.quickFacts();
// For reference: https://www.youtube.com/watch?v=9p2VeKRKZ1Q