Skip to content

Commit d881702

Browse files
committed
Classes Studio
1 parent 8a11108 commit d881702

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
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 total = 0;
13+
for (let i = 0; i < this.scores.length; i++) {
14+
total += this.scores[i];
15+
}
16+
let avg = total / this.scores.length;
17+
return Math.round(avg*10)/10
18+
19+
}
20+
status() {
21+
if (this.average() >= 90) {
22+
return "Accepted"
23+
} else if (this.average() >= 80) {
24+
return "Reserve"
25+
} else if (this.average() >= 70) {
26+
return "Probationary"
27+
} else {
28+
return "Rejected"
29+
}
30+
}
31+
}
32+
33+
let bear = new CrewCandidate("Bubba Bear", "135kg",[88, 85, 90,])
34+
let maltese = new CrewCandidate("Merry Maltese", "1.5kg", [93, 88, 97])
35+
let gator = new CrewCandidate("Glad Gator","225kg",[75, 78, 62])
36+
37+
38+
bear.addScore(83)
39+
let counter = 0;
40+
console.log(gator.average());
41+
while (gator.average() < 80) {
42+
gator.addScore(100)
43+
counter++;
44+
}
45+
// It takes 2 loops to reach Reserve and 6 to reach Accepted.
46+
47+
console.log(`${gator.name} earned an average test score of ${gator.average()}% and has a status of ${gator.status()}.`)
48+
console.log(counter)
249

350

451

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

754

855

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%.
56+
//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)