Let's create a class to handle new animal crew candidates!
Edit the practice file as you complete the studio activity.
constructorthat takes three parameters---
scores. Note that
scoreswill be an array of test results.
console.log for each object to verify that your class correctly assigns
the key/value pairs.
As our candidates complete more tests, we need to be able to add the new scores to their records.
CrewCandidate. The function must take a new score as a parameter. Code this function OUTSIDE of
constructor. (If you need to review the syntax, revisit Assigning Class Methods).
this.scoreswith the push array method.
83to Bubba's record, then print out the new score array with
Now that we can add scores to our candidates' records, we need to be able to
evaluate their fitness for our astronaut program. Let's add two more methods
CrewCandidate---one to average the test scores and the other to
indicate if the candidate should be admitted.
constructor. The function does NOT need a parameter.
this.scores, then divide the sum by the number of scores.
Verify your code by evaluating and printing Merry's average test score (92.7).
Candidates with averages at or above 90% are automatically accepted to our training program. Reserve candidates average between 80 - 89%, while probationary candidates average between 70 - 79%. Averages below 70% lead to a rejection notice.
CrewCandidate. The method returns a string (
Rejected) depending on a candidate's average.
statusmethod requires the average test score, which can be called as a parameter OR from inside the function. That's correct - methods can call other methods inside a class! Just remember to use the
statushas a candidate's average score, evaluate that score, and return the appropriate string.
statusmethod on each of the three candidates. Use a template literal to print out
'___ earned an average test score of ___% and has a status of ___.'
Use the three 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%.
Rather than adding one score at a time, could you use a loop?