Skip to content

Commit 49f39ed

Browse files
authored
Update ClassStudio.js
1 parent 19dd0ea commit 49f39ed

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,80 @@
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+
cheater() {
12+
this.scores.push(100);
13+
}
14+
average(){
15+
let sum = 0;
16+
for (let i=0; i<this.scores.length; i++){
17+
sum = sum + this.scores[i];
18+
}
19+
return (Math.round(10*(sum/(this.scores.length))))/10
20+
}
21+
status(averageScore=this.average()){
22+
if (averageScore>=90){
23+
return 'Accepted';
24+
} else if (averageScore >= 80) {
25+
return 'Reserve';
26+
} else if (averageScore >= 70) {
27+
return 'Probationary';
28+
} else {
29+
return 'Rejected';
30+
}
31+
}
32+
}
233

34+
let bear = new CrewCandidate('Bubba Bear', 135, [88,85,90]);
35+
let birdDog = new CrewCandidate('Merry Maltese', 1.5, [93,88,97]);
36+
let gator = new CrewCandidate('Glad Gator', 225, [75,78,62]);
337

438

39+
//bear.addScore(83);
40+
//console.log(bear.scores);
41+
//console.log(bear.status());
42+
//console.log(bear.average());
43+
//console.log(birdDog,bear,gator);
544
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
645

46+
while (!(gator.status() === 'Accepted')) {
47+
gator.cheater();
48+
}
749

50+
function display(candidate) {
51+
console.log(`${candidate.name} earned an average test score of ${candidate.average()}% and has a status of ${candidate.status()}.`);
52+
}
53+
display(bear)
54+
display(birdDog)
55+
display(gator)
56+
console.log(gator.scores);
57+
//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%.
858

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%.
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
//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.
73+
74+
75+
76+
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
77+
78+
79+
80+
//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)