Skip to content

Commit 6b9c5ba

Browse files
committed
Completed studio 11
1 parent 71b4686 commit 6b9c5ba

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
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+
}
9+
addScore(newScore){
10+
this.scores.push(newScore);
11+
}
12+
average() {
13+
let total = 0;
14+
this.scores.forEach((score)=> (total += score));
15+
let average = total / this.scores.length;
16+
return Math.round(average * 10) /10;
17+
}
18+
status() {
19+
let averageScore = this.average();
20+
if (averageScore >= 90) {
21+
return "Accepted";
22+
}else if (averageScore >= 80) {
23+
return "Reserve";
24+
}else if (averageScore >= 70) {
25+
return "Probationary";
26+
}else {
27+
return "Rejected";
28+
}
29+
}
30+
}
331

432

533
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
34+
let bear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
35+
let maltese = new CrewCandidate("Merry Maltese", 1.5, [93, 98, 97]);
36+
let gator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
637

38+
console.log(bear.name, bear.mass, bear.scores);
39+
console.log(maltese.name, maltese.mass, maltese.scores);
40+
console.log(gator.name, gator.mass, gator.scores);
741

842

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%.
43+
//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%.
44+
console.log(`${gator.name} is going to keep trying until he can pass!`);
45+
while (gator.status() !== "Accepted") {
46+
let testScore = Math.floor(Math.random()) * (100 - 80 + 1) + 80;
47+
gator.addScore(testScore);
48+
console.log(`${gator.name} scored ${testScore} on the last test and now his average is ${gator.average()}`);
49+
}

0 commit comments

Comments
 (0)