Skip to content

Commit 730003e

Browse files
committed
completed studio
1 parent fddfdd1 commit 730003e

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

classes/studio/ClassStudio.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,67 @@
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+
// let total = this.scores.reduce((a,b));
14+
for (let i = 0; i < this.scores.length; i++){
15+
total += this.scores[i];
16+
}
17+
let avg = total / this.scores.length;
18+
avg = Math.round(avg * 10) / 10;
19+
return avg
20+
}
21+
status(average) {
22+
if (average >= 90) {
23+
return 'accepted';
24+
} else if (average >= 80) {
25+
return 'reserved';
26+
} else if (average >= 70) {
27+
return 'probationary';
28+
} else {
29+
return 'rejection';
30+
}
31+
}
32+
}
233

334

35+
let bear = new CrewCandidate('Bubba Bear', 135, [88, 85, 90]);
36+
let dog = new CrewCandidate('Merry Maltese', 1.5, [93, 88, 97]);
37+
let alligator = new CrewCandidate('Glad Gator', 225, [75, 78, 62]);
38+
39+
// console.log(bear);
40+
// console.log(dog);
41+
// console.log(alligator);
42+
// bear.addScore(83)
43+
44+
// console.log(bear)
45+
// console.log(bear.average())
46+
47+
console.log(alligator.status(alligator.average()));
48+
console.log(bear.status(bear.average()));
49+
console.log(dog.status(dog.average()))
50+
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%.
57+
alligator.addScore(100);
58+
alligator.addScore(100);
59+
alligator.addScore(100);
60+
alligator.addScore(100);
61+
alligator.addScore(100);
62+
alligator.addScore(100);
63+
64+
console.log(alligator.status(alligator.average()));
65+
66+
console.log(`${alligator.name} earned an average test score of ${alligator.average()}% and has a status of ${alligator.status(alligator.average())}.`)
67+

0 commit comments

Comments
 (0)