You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Declare a class called CrewCandidate with a constructor that takes three parameters—name, mass, and scores. Note that scores will be an array of test results.
2
+
3
+
classCrewCandidate{
4
+
constructor(name,mass,scores){
5
+
// assign properties with this.key = value
6
+
this.name=name;
7
+
this.mass=mass;
8
+
this.scores=scores;
9
+
}
10
+
11
+
// PART 2 - Method adds new scores to 'scores' array
12
+
addScore(newScore){
13
+
//function code
14
+
if(typeofnewScore==="object"){
15
+
for(leti=0;i<newScore.length;i++){
16
+
this.scores.push(newScore[i]);
17
+
}
18
+
}else{
19
+
this.scores.push(newScore);
20
+
}
21
+
}
22
+
23
+
// PART 3 - Method that Calculates the Test Average from scores in 'scores' array
24
+
average(){
25
+
lettotalScores=0;
26
+
letavgScore=0;
27
+
letroundedAvgScore=0;
28
+
29
+
// Using For Loop to add each element in array
30
+
for(leti=0;i<this.scores.length;i++){
31
+
totalScores+=this.scores[i];
32
+
}
33
+
34
+
avgScore=(totalScores/this.scores.length);
35
+
roundedAvgScore=Math.round(avgScore*10)/10;
36
+
returnroundedAvgScore;
37
+
}
38
+
39
+
// PART 3 - Method that determines Candidate Status
40
+
status(){
41
+
letstatus="";
42
+
if(this.average()>=90&&this.average()<=100){
43
+
status="Accepted";
44
+
}elseif(this.average()>=80&&this.average()<90){
45
+
status="Reserve";
46
+
}elseif(this.average()>=70&&this.average()<80){
47
+
status="Probationary";
48
+
}elseif(this.average()<70){
49
+
status="Rejected"
50
+
}else{
51
+
status="INVALID Score. Try again!";
52
+
}
53
+
console.log(`${this.name} earned an average test score of ${this.average()}% and has a status of "${status}"`);
console.log(`${candidateMerryMaltese.name}'s Average Test Score: ${candidateMerryMaltese.average()}\n`);
84
+
85
+
86
+
//Verifying that Part 3 - status() method works
87
+
console.log(candidateMerryMaltese.status());
88
+
console.log(candidateBubbaBear.status());
89
+
console.log(candidateGladGator.status());
90
+
console.log("");
91
+
92
+
93
+
94
+
95
+
96
+
//Part 4 - Use the methods to boost Glad Gator’s status to Reserve or higher. How many tests will it take to reach Reserve status? How many to reach Accepted? Remember, scores cannot exceed 100%.
97
+
98
+
// Using while loop to boost Glad Gator's status to "Reserve" - How many test will it take to reach "Reserve" status?
0 commit comments