forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassStudio.js
More file actions
64 lines (56 loc) · 1.71 KB
/
Copy pathClassStudio.js
File metadata and controls
64 lines (56 loc) · 1.71 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
class CrewCandidate {
constructor(name, mass, scores) {
this.name = name;
this.mass = mass;
this.scores = scores;
}
addScore(newScore) {
this.scores.push(newScore);
}
average() {
let sum = 0;
for (let i = 0; i < this.scores.length; i++) {
sum += this.scores[i];
}
const avg = sum / this.scores.length;
return Math.round(avg * 10) / 10;
}
status() {
let avgScore = this.average();
if (avgScore >= 90) {
return "Accepted";
} else if (avgScore >= 80) {
return "Reserve";
} else if (avgScore >= 70) {
return "Probationary";
} else {
return "Rejected";
}
}
}
let bubbaBear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
let merryMaltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
let gladGator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
function calculateTestsForStatusUpgrade(candidate, upgradeStatus) {
let testsAdded = 0;
while (candidate.status() !== upgradeStatus) {
candidate.addScore(100);
testsAdded++;
if (candidate.status() === upgradeStatus) break;
}
return testsAdded;
}
let testsForReserve = calculateTestsForStatusUpgrade(gladGator, "Reserve");
let gladGatorReserveStatus = gladGator.status();
let testsForAccepted = calculateTestsForStatusUpgrade(gladGator, "Accepted");
console.log(`Tests needed for Glad Gator to reach Reserve: ${testsForReserve}`);
console.log(
`Additional tests needed for Glad Gator to reach Accepted: ${testsForAccepted}`
);
[bubbaBear, merryMaltese, gladGator].forEach((candidate) => {
console.log(
`${
candidate.name
} earned an average test score of ${candidate.average()}% and has a status of ${candidate.status()}.`
);
});