Skip to content

Commit 0dd0527

Browse files
Quinton KornegayQuinton Kornegay
authored andcommitted
10.23.23
1 parent 61d49bb commit 0dd0527

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

classes/studio/ClassStudio.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
//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-
2+
class CrewCandidate {
3+
constructor(name, mass, scores){
4+
this.name = name;
5+
this.mass = mass;
6+
this.scores = scores;
7+
}
8+
addScore(score) {
9+
this.scores.push(score);
10+
}
11+
average() {
12+
let sum = 0;
13+
for (let i = 0; i < this.scores.length; i++) {
14+
sum += this.scores[i];
15+
}
16+
return Math.round(10 * sum / this.scores.length) / 10;
17+
}
18+
status() {
19+
let avg = this.average()
20+
if (avg >= 90) {
21+
return 'Accepted';
22+
} else if (avg >= 80) {
23+
return 'Reserve';
24+
} else if (avg >= 70) {
25+
return 'Probationary';
26+
} else {
27+
return 'Rejected';
28+
}
29+
}
30+
}
431

532
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
33+
let bubba = new CrewCandidate('Bubba Bear', 135, [88, 85, 90]);
34+
let merry = new CrewCandidate('Merry Maltese', 1.5, [93, 88, 97]);
35+
let glad = new CrewCandidate('Glad Gator', 225, [75, 78, 62]);
636

37+
let candidates = [bubba, merry, glad];
38+
for (let j = 0; j < candidates.length; j++) {
39+
console.log(`\n${candidates[j].name} earned an avergae test score of ${candidates[j].average()}% and has an average of ${candidates[j].average()}% and a status of ${candidates[j].status()}.`);
40+
}
41+
742

43+
//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%.
844

9-
//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%.
45+
let reserveCount = 0;
46+
while (glad.status() !== 'Reserve') {
47+
glad.addScore(100);
48+
reserveCount ++;
49+
}
50+
console.log(glad.scores);
51+
console.log(`\nIt took ${reserveCount} perfect scores to get Glad Gator up to Reserve Status!`)

0 commit comments

Comments
 (0)