Skip to content

Commit cd458e3

Browse files
committed
Studio complete
1 parent f1c1694 commit cd458e3

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,64 @@
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+
}
8+
addScore(newScore){
9+
this.scores.push(newScore);
10+
}
11+
average(){
12+
let sumOfScores = 0;
13+
for (let i = 0; i < this.scores.length; i++){
14+
sumOfScores += this.scores[i];
15+
}
16+
return (sumOfScores/ this.scores.length).toFixed(1);
17+
}
18+
status(){
19+
let average = this.average();
20+
if (average >= 90)
21+
return "Accepted";
22+
else if (average >= 80)
23+
return "Reserve";
24+
else if (average >= 70)
25+
return "Probationary";
26+
else
27+
return "Rejected";
28+
}
29+
}
230

31+
let candidate1 = new CrewCandidate ("Bubba Bear", 135, [88, 85, 90]);
32+
let candidate2 = new CrewCandidate ("Mary Maltese", 1.5, [93, 88, 97]);
33+
let candidate3 = new CrewCandidate ("Glad Gator", 225, [75, 78, 62]);
334

35+
console.log(candidate1);
36+
console.log(candidate2);
37+
console.log(candidate3);
438

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

41+
candidate1.addScore(83);
42+
console.log(candidate1.scores);
43+
console.log(candidate2.average());
744

45+
console.log(`${candidate1.name} earned an average test score of ${candidate1.average()}% and has a status of ${candidate1.status()}.
46+
${candidate2.name} earned an average test score of ${candidate2.average()}% and has a status of ${candidate2.status()}.
47+
${candidate3.name} earned an average test score of ${candidate3.average()}% and has a status of ${candidate3.status()}.
48+
`)
849

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%.
50+
//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%.
51+
52+
while (candidate3.status() !== "Reserve"){
53+
candidate3.addScore(100);
54+
};
55+
console.log(`It took ${candidate3.scores.length} tests to reach Reserve status.
56+
`
57+
);
58+
while (candidate3.status() !== "Accepted"){
59+
candidate3.addScore(100);
60+
};
61+
62+
console.log(`It took ${candidate3.scores.length} tests to reach Accepted status.
63+
`
64+
);

0 commit comments

Comments
 (0)