Skip to content

Commit 0d08eca

Browse files
committed
Classwork
1 parent 79f26ee commit 0d08eca

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

classes/studio/ClassStudio.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
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+
}
312

13+
average() {
14+
let sum = 0;
15+
for (let i = 0; i < this.scores.length; i++) {
16+
sum += this.scores[i];
17+
}
18+
let roundedAverage = Math.round(sum / this.scores.length * 100)/100
19+
return roundedAverage;
20+
}
21+
22+
status() {
23+
if (this.average() >= 90) {
24+
return "accepted";
25+
} else if (this.average() >= 90) {
26+
return "Reserve";
27+
} else if (this.average >= 70){
28+
return "Probationary";
29+
} else {
30+
return "Rejected";
31+
}
32+
}
33+
}
34+
35+
const kondo = new CrewCandidate("Kondo", "100", [95, 98, 90]);
36+
37+
console.log(kondo);
38+
39+
const bubbaBear = new CrewCandidate("Bubba Bear", "135", [88, 85, 90]);
40+
bubbaBear.addScore(78);
41+
console.log(bubbaBear);
42+
console.log(bubbaBear.average());
43+
44+
const merryMaltese = new CrewCandidate("Merry Maltese", "1.5", [93, 88, 97]);
45+
46+
console.log(merryMaltese);
47+
48+
const gladGator = new CrewCandidate("Glad Gator", "225", [75, 78, 62]);
49+
50+
console.log(gladGator);
451

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

754

55+
console.log(`${bubbaBear.name} earned an average test score of ${bubbaBear.average()}% and has a status of ${bubbaBear.status()}.`)
56+
console.log(`${merryMaltese.name} earned an average test score of ${merryMaltese.average()}% and has a status of ${merryMaltese.status()}.`)
57+
console.log(`${gladGator.name} earned an average test score of ${gladGator.average()}% and has a status of ${gladGator.status()}.`)
58+
859

960
//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)