-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassSyntax.js
More file actions
54 lines (49 loc) · 1.1 KB
/
classSyntax.js
File metadata and controls
54 lines (49 loc) · 1.1 KB
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
class Student {
constructor(firstName, lastName, year) {
this.firstName = firstName;
this.lastName = lastName;
this.grade = year;
this.tardies = 0;
this.scores = [];
console.log(this);
}
fullName() {
return `Your full name is ${this.firstName} ${this.lastName}`;
}
markLate() {
this.tardies += 1;
if (this.tardies >= 3) {
return 'YOU ARE EXPELLED!!!!';
}
return `${this.firstName} ${this.lastName} has been late ${this.tardies} times`;
}
addScore(score) {
this.scores.push(score);
return this.scores;
}
calculateAverage() {
let sum = this.score.reduce(function (a, b) {
return a + b;
});
return sum / this.scores.length;
}
static EnrollStudents() {
return 'Enrolling Students';
}
}
let firstStudent = new Student('Jonathan', 'Gomez', 3);
//firstStudent.fullName();
// MDN Docs
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
static distance(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
return Math.hypot(dx, dy);
}
}
const p1 = new Point(5, 5);
const p2 = new Point(10, 10);