Skip to content

Commit 78e227c

Browse files
Charlene TranCharlene Tran
Charlene Tran
authored and
Charlene Tran
committed
CT completed
1 parent d5beb88 commit 78e227c

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

classes/studio/ClassStudio-CT.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//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+
3+
class CrewCandidate {
4+
constructor(name, mass, scores) {
5+
// assign properties with this.key = value
6+
this.name = name;
7+
this.mass = mass;
8+
this.scores = scores;
9+
}
10+
11+
// PART 2 - Method adds new scores to 'scores' array
12+
addScore(newScore) {
13+
//function code
14+
if (typeof newScore === "object") {
15+
for (let i = 0; i < newScore.length; i++) {
16+
this.scores.push(newScore[i]);
17+
}
18+
} else {
19+
this.scores.push(newScore);
20+
}
21+
}
22+
23+
// PART 3 - Method that Calculates the Test Average from scores in 'scores' array
24+
average() {
25+
let totalScores = 0;
26+
let avgScore = 0;
27+
let roundedAvgScore = 0;
28+
29+
// Using For Loop to add each element in array
30+
for (let i = 0; i < this.scores.length; i++) {
31+
totalScores += this.scores[i];
32+
}
33+
34+
avgScore = (totalScores / this.scores.length);
35+
roundedAvgScore = Math.round(avgScore * 10) / 10;
36+
return roundedAvgScore;
37+
}
38+
39+
// PART 3 - Method that determines Candidate Status
40+
status() {
41+
let status = "";
42+
if (this.average() >= 90 && this.average() <= 100) {
43+
status = "Accepted";
44+
} else if (this.average() >= 80 && this.average() < 90) {
45+
status = "Reserve";
46+
} else if (this.average() >= 70 && this.average() < 80) {
47+
status = "Probationary";
48+
} else if (this.average() < 70) {
49+
status = "Rejected"
50+
} else {
51+
status = "INVALID Score. Try again!";
52+
}
53+
console.log(`${this.name} earned an average test score of ${this.average()}% and has a status of "${status}"`);
54+
return status;
55+
}
56+
57+
58+
59+
}
60+
61+
// Creating Objects for the following candidates
62+
let candidateBubbaBear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
63+
let candidateMerryMaltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
64+
let candidateGladGator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
65+
66+
// Verifying Part 1 works
67+
console.log(candidateBubbaBear);
68+
console.log(candidateMerryMaltese);
69+
console.log(candidateGladGator);
70+
71+
72+
73+
74+
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
75+
76+
//Verifying that Part 2 - addScore() method works
77+
candidateBubbaBear.addScore(83);
78+
console.log(candidateBubbaBear.scores);
79+
80+
81+
//Verifying that Part 3 - average() method works
82+
console.log(`${candidateMerryMaltese.name}'s scores: ${candidateMerryMaltese.scores}`);
83+
console.log(`${candidateMerryMaltese.name}'s Average Test Score: ${candidateMerryMaltese.average()}\n`);
84+
85+
86+
//Verifying that Part 3 - status() method works
87+
console.log(candidateMerryMaltese.status());
88+
console.log(candidateBubbaBear.status());
89+
console.log(candidateGladGator.status());
90+
console.log("");
91+
92+
93+
94+
95+
96+
//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%.
97+
98+
// Using while loop to boost Glad Gator's status to "Reserve" - How many test will it take to reach "Reserve" status?
99+
let boostGladGatorReserve = function () {
100+
let numTimes = 0;
101+
102+
while (candidateGladGator.status() !== "Reserve") {
103+
candidateGladGator.addScore(100)
104+
numTimes += 1;
105+
}
106+
console.log("");
107+
console.log(`${candidateGladGator.name}'s scores: ${candidateGladGator.scores}`);
108+
return `It took ${candidateGladGator.name} ${numTimes} tests of 100% score to reach ${candidateGladGator.status()}!\n`;
109+
}
110+
111+
console.log(boostGladGatorReserve());
112+
113+
114+
115+
// Using while loop to boost Glad Gator's status to "Accepted" - How many test will it take to reach "Accepted" status?
116+
let boostGladGatorAccepted = function() {
117+
let numTimes = 0;
118+
119+
while (candidateGladGator.status() !== "Accepted") {
120+
candidateGladGator.addScore(100)
121+
numTimes += 1;
122+
}
123+
console.log("");
124+
console.log(`${candidateGladGator.name}'s scores: ${candidateGladGator.scores}`);
125+
return `It took ${candidateGladGator.name} ${numTimes} more tests of 100% score to reach ${candidateGladGator.status()}!\n`;
126+
}
127+
128+
console.log(boostGladGatorAccepted());

0 commit comments

Comments
 (0)