Skip to content

Commit 169085f

Browse files
committed
complete
1 parent 31f07db commit 169085f

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

classes/studio/ClassStudio.js

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,64 @@
1-
//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.
21
class CrewCandidate {
32
constructor(name, mass, scores) {
43
this.name = name;
5-
this.mass = name;
4+
this.mass = mass;
65
this.scores = scores;
76
}
7+
8+
addScore(newScore) {
9+
this.scores.push(newScore);
10+
}
11+
12+
average() {
13+
let sum = 0;
14+
for (let i = 0; i < this.scores.length; i++) {
15+
sum += this.scores[i];
16+
}
17+
const avg = sum / this.scores.length;
18+
return Math.round(avg * 10) / 10;
19+
}
20+
21+
status() {
22+
let avgScore = this.average();
23+
if (avgScore >= 90) {
24+
return "Accepted";
25+
} else if (avgScore >= 80) {
26+
return "Reserve";
27+
} else if (avgScore >= 70) {
28+
return "Probationary";
29+
} else {
30+
return "Rejected";
31+
}
32+
}
833
}
34+
935
let bubbaBear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
1036
let merryMaltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
1137
let gladGator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
1238

13-
console.log("Bubba Bear:", bubbaBear);
14-
console.log("Merry Maltese:", merryMaltese);
15-
console.log("Glad Gator:", gladGator);
39+
function calculateTestsForStatusUpgrade(candidate, upgradeStatus) {
40+
let testsAdded = 0;
41+
while (candidate.status() !== upgradeStatus) {
42+
candidate.addScore(100);
43+
testsAdded++;
44+
if (candidate.status() === upgradeStatus) break;
45+
}
46+
return testsAdded;
47+
}
48+
49+
let testsForReserve = calculateTestsForStatusUpgrade(gladGator, "Reserve");
50+
let gladGatorReserveStatus = gladGator.status();
51+
let testsForAccepted = calculateTestsForStatusUpgrade(gladGator, "Accepted");
1652

17-
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
53+
console.log(`Tests needed for Glad Gator to reach Reserve: ${testsForReserve}`);
54+
console.log(
55+
`Additional tests needed for Glad Gator to reach Accepted: ${testsForAccepted}`
56+
);
1857

19-
//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%.
58+
[bubbaBear, merryMaltese, gladGator].forEach((candidate) => {
59+
console.log(
60+
`${
61+
candidate.name
62+
} earned an average test score of ${candidate.average()}% and has a status of ${candidate.status()}.`
63+
);
64+
});

classes/studio/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)