Skip to content

Commit f09d89e

Browse files
author
Edward King
committed
Studio complete
1 parent 3bd8e29 commit f09d89e

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 @@
1+
2+
3+
14
//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.
25

6+
class CrewCandidate {
7+
constructor(name, mass, scores) {
8+
this.name = name;
9+
this.mass = mass;
10+
this.scores = scores;
11+
}
12+
13+
addScore(newScore) {
14+
this.scores.push(newScore);
15+
}
16+
17+
average() {
18+
let sum = 0;
19+
for (let i = 0; i < this.scores.length; i++) {
20+
sum += this.scores[i];
21+
}
22+
let mean = sum / this.scores.length;
23+
return Math.round(mean * 10) / 10;
24+
}
25+
26+
status() {
27+
let scoreAverage = this.average();
28+
//Why did the score average need to be stored as something else in order to work correctly?
29+
if (scoreAverage >= 90) {
30+
return "Accepted!";
31+
} else if (scoreAverage >= 80) {
32+
return "Reserve";
33+
} else if (scoreAverage >= 70) {
34+
return "Probationary";
35+
} else {
36+
return "Rejected";
37+
}
38+
}
39+
40+
}
41+
42+
const bubba = new CrewCandidate("Bubba", 135, [88, 85, 90]);
43+
const merry = new CrewCandidate("Merry", 1.5, [93, 88, 97]);
44+
const glad = new CrewCandidate("Glad", 225, [75, 78, 62]);
45+
46+
console.log(bubba);
47+
console.log(merry);
48+
console.log(glad);
49+
50+
bubba.addScore(83);
51+
console.log(bubba.scores);
52+
53+
console.log(merry.average());
54+
355

56+
console.log(`${bubba.name} earned an average test score of ${bubba.average()} and has a status of ${bubba.status()}`)
57+
console.log(`${merry.name} earned an average test score of ${merry.average()} and has a status of ${merry.status()}`)
58+
console.log(`${glad.name} earned an average test score of ${glad.average()} and has a status of ${glad.status()}`)
459

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

762

863

9-
//Part 4 - Use the methods to boost Glad Gators 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%.
64+
//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)