-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay12-Inheritance.js
More file actions
79 lines (67 loc) · 2.1 KB
/
Copy pathDay12-Inheritance.js
File metadata and controls
79 lines (67 loc) · 2.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
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
/**
* 1. The Student class extends the Person class.
* 2. The Student constructor takes the same parameters as the Person constructor.
* 3. The Student constructor calls the Person constructor to initialize the firstName, lastName, and id properties.
* 4. The Student constructor creates a new property, scores, and assigns it to an array.
* 5. The Student constructor calls the calculate method to calculate the average score and assign it to the average property.
* 6. The calculate method calculates the average score and returns the letter grade.
* 7. The Student constructor returns the new Student object.
*/
class Student extends Person {
/**
* Class Constructor
*
* @param firstName - A string denoting the Person's first name.
* @param lastName - A string denoting the Person's last name.
* @param id - An integer denoting the Person's ID number.
* @param scores - An array of integers denoting the Person's test scores.
*/
// Write your constructor here
/**
* Method Name: calculate
* @return A character denoting the grade.
*/
// Write your method here
/**
* The above code is creating a class called Student that inherits from the Person class. It is also
* creating a method called calculate that will return a letter grade based on the average of the
* scores array.
*/
constructor(firstName, lastName, id, scores) {
super(firstName, lastName, id);
this.scores = scores;
}
calculate() {
const average =
this.scores.reduce((target, score) => {
return target + score;
}) / this.scores.length;
const range =
average < 70
? Math.ceil((100 - average) / 15)
: Math.floor((100 - average - 1) / 10);
let letter = "";
switch (range) {
case -1:
case 0:
letter = "O";
break;
case 1:
letter = "E";
break;
case 2:
letter = "A";
break;
case 3:
letter = "P";
break;
case 4:
letter = "D";
break;
default:
letter = "T";
break;
}
return letter;
}
}