Skip to content

Commit 0d79608

Browse files
committed
classes studio
1 parent 93fe1e4 commit 0d79608

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

classes/studio/ClassStudio.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,63 @@
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+
class CrewCandidate {
3+
constructor(name, mass, scores) {
4+
this.name = name;
5+
this.mass = mass;
6+
this.scores = scores;
7+
}
28

9+
addScore(newScore) {
10+
this.scores.push(newScore);
11+
}
312

13+
averageScores() {
14+
let sum = 0;
15+
this.scores.forEach(item => {
16+
sum += item;
17+
});
18+
return Math.round((sum / this.scores.length) * 10) / 10;
19+
}
20+
21+
status() {
22+
let currentStatus = "";
23+
if (this.averageScores() >= 90) {
24+
currentStatus = 'Accepted';
25+
} else if (this.averageScores() >= 80 && this.averageScores() < 90) {
26+
currentStatus = 'In Reserve';
27+
} else if (this.averageScores() >= 70 && this.averageScores() < 80) {
28+
currentStatus = 'On Probation';
29+
} else {
30+
currentStatus = 'Declined';
31+
}
32+
return `${this.name} earned an average test score of ${this.averageScores()} and has a status of "${currentStatus}".`;
33+
}
34+
}
35+
36+
let bubba = new CrewCandidate('Bubba Bear', 135, [88, 85, 90]);
37+
let merry = new CrewCandidate('Merry Maltese', 1.5, [93, 88, 97]);
38+
let glad = new CrewCandidate('Glad Gator', 225, [75, 78, 62]);
39+
40+
console.log(bubba, merry, glad);
41+
42+
bubba.addScore(83);
43+
console.log(bubba.scores);
44+
console.log(`Merry's average: ${merry.averageScores()}`);
445

546
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
647

48+
function getToAccepted(animal) {
49+
if (animal.averageScores() >= 90) {
50+
console.log(`${animal.name} has already been accepted.`);
51+
} else {
52+
let count = 0;
53+
while (animal.averageScores() < 90) {
54+
animal.addScore(100);
55+
count++;
56+
console.log(`Test: ${count}\n${animal.status()}`);
57+
}
58+
}
59+
}
760

61+
getToAccepted(glad);
862

963
//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%.

0 commit comments

Comments
 (0)