Skip to content

Commit b21646e

Browse files
committed
modified: classes/studio/ClassStudio.js
1 parent ef4a794 commit b21646e

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,77 @@
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.
22

3+
class CrewCandidate {
4+
constructor(name, mass, scores) {
5+
this.name = name;
6+
this.mass = mass;
7+
this.scores = scores;
8+
}
39

10+
addScore(score) {
11+
return this.scores.push(score);
12+
}
13+
14+
avgScore() {
15+
let sum = 0;
16+
for (let i = 0; i < this.scores.length; i++) {
17+
sum += this.scores[i];
18+
}
19+
return sum / this.scores.length;
20+
}
21+
22+
status(val = this.avgScore()) {
23+
let stat = ''
24+
25+
if (val >= 90) {
26+
stat = 'Accepted'
27+
} else if (val >= 80 ) {
28+
stat = 'Reserve'
29+
} else if (val >= 70 ) {
30+
stat = 'Probationary'
31+
} else {
32+
stat = 'Rejected'
33+
}
34+
35+
console.log(`${this.name} earned an average test score of ${val}% and has a status of ${stat}.`)
36+
}
37+
}
38+
39+
let bubbaBear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
40+
let merryMaltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
41+
let gladGator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
42+
43+
console.log(bubbaBear);
44+
console.log(merryMaltese);
45+
console.log(gladGator);
46+
47+
bubbaBear.addScore(83)
48+
49+
console.log(bubbaBear.scores)
50+
51+
console.log(merryMaltese.avgScore())
52+
53+
console.log(merryMaltese.status())
454

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

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%.
58+
59+
let sum = 0
60+
61+
while (gladGator.avgScore() <= 80) {
62+
gladGator.addScore(100)
63+
sum += 1
64+
65+
}
66+
67+
console.log (`It took ${sum} perfect scores to get ${gladGator.name} to Reserve`)
68+
69+
sum = 0
70+
71+
while (gladGator.avgScore() <= 90) {
72+
gladGator.addScore(100)
73+
sum += 1
774

75+
}
876

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%.
77+
console.log (`It took ${sum} perfect scores to get ${gladGator.name} to Accepted`)

0 commit comments

Comments
 (0)